----------------------------------------------------------------------------- -- -- Onions Network Streams Library -- -- O N I O N S . O S -- -- S p e c -- -- Copyright (C) 1997-1998 Regents of the University of California -- -- Onions is free software; you can redistribute it and/or modify it under -- the terms of the GNU General Public License as published by the Free -- Software Foundation, with or without the single exception listed below; -- either version 2, or (at your option) any later version. Onions is -- distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -- without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -- PARTICULAR PURPOSE. See the GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- distributed with Onions; see the file COPYING. If not, write to the -- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -- 02111-1307, USA. -- -- As a special exception, if other files instantiate generics from this -- library, or you link this library with other files to produce an -- executable, this library does not by itself cause the resulting -- executable to be covered by the GNU General Public License. This -- exception does not however invalidate any other reasons why the -- executable file might be covered by the GNU General Public License. -- -- Portions of this unit have been derived from version 1.02 of the Garlic -- library of GLADE, the Ada95 Distributed Systems Annex for GNAT. GLADE -- is maintained by ACT Europe (see ). -- -- GLADE is Copyright (C) 1996,1997 Free Software Foundation, Inc. -- All source code that is shared by both GLADE version 1.02 and -- this unit remains under the FSF copyright. -- -- Rewritten for Onions in 1997 by Roy T. Fielding ----------------------------------------------------------------------------- -- -- The OS package provides a slightly thicker binding to some -- operating system-dependent routines. The package spec is -- generated by configure from this template file, so portability problems -- should be fixed via hooks within this package and os-depend.c. -- with Ada.Exceptions; with Interfaces.C.Strings; with System.Storage_Elements; with Onions.Thin; use Onions.Thin; package Onions.OS is -- Raise_Error patches together a meaningful error message to -- go along with a raised exception. If Errno is non-zero, suffix -- the Message with the system error string [strerror(errno)]. -- procedure Raise_Error (Ex_ID : in Ada.Exceptions.Exception_Id; Errno : in C.Int; Message : in String); -- Return the value of the environment variable Name or an empty -- string if this variable doesn't exist. -- function Getenv (Name : String) return String; -- Set the open file descriptor to non-blocking mode -- and return Failure or Success. -- function Set_Non_Blocking (Filedes : Descriptor) return C.int; -------------------------------------------- -- Interface to routines in os-depend.c -- -------------------------------------------- -- Get thread-safe C errno. -- function C_errno return C.int; -- Set thread-safe C errno. -- procedure Set_Errno (New_Errno : C.int); -- Get system-independent file/link/fd stats -- type Stat_Record is record file_mode : C.unsigned_long; -- mode_t file_ino : C.unsigned_long; -- ino_t file_dev : C.unsigned_long; -- dev_t file_nlink : C.unsigned_long; -- nlink_t file_uid : C.long; -- uid_t file_gid : C.long; -- gid_t file_size : C.long; -- off_t file_atime : C.long; -- time_t file_mtime : C.long; -- time_t file_ctime : C.long; -- time_t end record; pragma Convention (C, Stat_Record); type Stat_Access is access all Stat_Record; pragma Convention (C, Stat_Access); function Stat (Path : C.Strings.chars_ptr; Buf : Stat_Access) return C.int; function Lstat (Path : C.Strings.chars_ptr; Buf : Stat_Access) return C.int; function Fstat (Fd : Descriptor; Buf : Stat_Access) return C.int; -- Wait_For_Fd uses the poll or select system call to stop -- the thread until the descriptor indicates an error, eof, or the -- availability of something to read/write/both (depending on the value -- of Fd_State being Fd_Readable/Fd_Writable/Fd_Read_or_Write). -- If Timeout > 0, then we wait for a maximum of Timeout milliseconds. -- Returns -1 if an error occurs (see C_errno), -- 0 if the timeout period expires, or -- >0 if the descriptor becomes ready. -- function Wait_For_Fd (Fd_State : C.int; Filedes : Descriptor; Timeout : Natural) return C.int; Fd_Readable : constant C.int := 1; Fd_Writable : constant C.int := 2; Fd_Read_or_Write : constant C.int := 3; -- Readdir reads the already open directory pointed to by Dir_Ptr and -- places the next filename in the provided Buf of max length Buflen. -- NOTE: Buflen should be at least NAME_MAX + 1. -- Returns -1 on error (see errno), 0 on end-of-dir, or the length -- of the filename placed in the buffer. -- function Readdir (Dir_Ptr : DIR_Address; Buf : System.Address; Buflen : System.Storage_Elements.Storage_Count) return System.Storage_Elements.Storage_Offset; New_Line : constant String := @OS_NEW_LINE_AGGREGATE@; private pragma Import (C, C_errno, "onions_get_errno"); pragma Import (C, Set_Errno, "onions_set_errno"); pragma Import (C, Stat, "onions_stat"); pragma Import (C, Lstat, "onions_lstat"); pragma Import (C, Fstat, "onions_fstat"); pragma Import (C, Wait_For_Fd, "onions_wait_for_fd"); pragma Import (C, Readdir, "onions_readdir"); @OS_LINKER_OPTS@ end Onions.OS;