-- -- -------------------------------------------------------------------------------- -- -- Runtime_Support_Library -- -- This package provides an Ada binding to a subset of the -- interfaces specified in IEEE std 1003.1:1990; referred to -- as POSIX. For a complete description of these routines -- and their parameters, refer to the POSIX standard. Currently -- POSIX is defined by the C language. Therefore, most of the -- types exported by this package are the Ada representations -- of C types. -- -- Not all routines in the POSIX standard are implemented as C -- functions. Some of the routines are implemented as "pseudo- -- functions". There is no way for Ada to interface to these -- "pseudo-functions". For these functions, an interface to -- a C function which implements the desired operation is -- performed. -- -- The package is divided in two major parts. The first part -- exports the functions to manipulate files and directories. -- The second part exports the routines to execute processes -- and obtain process attributes. -- -- -- -- -- Gerardo A. Colon -- 18 September 1990 -- -- Science Applications International Corporation --
311 Park Place Boulevard, Suite 360 --
Clearwater, Florida 34619 -- -- Developed for the STARS program under task S40. -- -- -- -- -- Dependencies => -- ( Operating_System => AIX , -- Compiler => IBM RT PC , -- Device => None ) ; -- -- -------------------------------------------------------------------------------- with C_String_Utilities ; with Interface_Definitions ; with System ; use C_String_Utilities ; use Interface_Definitions ; pragma Elaborate ( C_String_Utilities ) ; pragma Elaborate ( Interface_Definitions ) ; pragma Page ; -------------------------------------------------------------------------------- -- package Runtime_Support_Library (specification). -------------------------------------------------------------------------------- package Runtime_Support_Library is -- -- Note: Unless otherwise specified, an integer value returned by any of the -- functions in this package is a status value. If the function completes -- successfully it will return 0. Otherwise, the function will return -1. -- type Dir is record Dd_Fd : Interface_Integer ; Dd_Loc : Interface_Long ; Dd_Size : Interface_Long ; Dd_Flag : Interface_Long ; Dd_Blksize : Interface_Integer ; Dd_Buf : String_Pointer ; Dd_Bbase : Interface_Long ; Dd_Xbase : Interface_Long ; end record ; -- -- This record defines a directory structure which is used to identify a -- directory in the file system. -- subtype Dir_Link is System.Address ; -- -- This type defines a reference to a directory structure. -- type Stat_Structure is record St_Dev : Interface_Integer ; St_Ino : Interface_Ushort ; St_Mode : Interface_Ushort ; St_Nlink : Interface_Short ; St_Uid : Interface_Ushort ; St_Gid : Interface_Ushort ; St_Rdev : Interface_Integer ; St_Size : Interface_Long ; St_Atime : Interface_Long ; St_Mtime : Interface_Long ; St_Ctime : Interface_Long ; end record ; -- -- This structure defines the information maintained by the system regarding a -- file. -- subtype Stat_Structure_Link is System.Address ; -- -- This type defines a reference to a Stat_Structure record. -- Name_Max : constant := 256 ; -- -- This constant defines the maximum number length for a file name in the -- system. -- type Name_Buffer is array ( 1 .. Name_Max ) of Character ; -- -- This type is used to store the file names of the files in the system. -- type Directory_Entry is record D_Ino : Interface_Ulong ; D_Reclen : Interface_Ushort ; D_Namlen : Interface_Ushort ; D_Name : Name_Buffer ; end record ; -- -- This type defines all the information required by the system to manipulate -- a directory entry. -- subtype Directory_Entry_Link is System.Address ; -- -- This type defines a reference to a directory entry. -- S_IRWXU : constant Interface_Definitions.Interface_Integer := 448 ; S_IRWXG : constant Interface_Definitions.Interface_Integer := 56 ; S_IRWXO : constant Interface_Definitions.Interface_Integer := 7 ; -- -- These constants define values to be used when specifying the access of -- a file's owner, group, or others. -- All_Permissions : constant Interface_Definitions.Interface_Integer := S_IRWXU + S_IRWXG + S_IRWXO ; -- -- This constant defines an access which allows reading, writing, and execute -- access to the file's owner, group, and others. -- R_OK : constant Interface_Definitions.Interface_Integer := 4 ; W_OK : constant Interface_Definitions.Interface_Integer := 2 ; X_OK : constant Interface_Definitions.Interface_Integer := 1 ; -- -- These constants define values used to check if a particular access is -- allowed on a file. -- O_RDONLY : constant Interface_Definitions.Interface_Integer := 0 ; O_WRONLY : constant Interface_Definitions.Interface_Integer := 1 ; O_CREAT : constant Interface_Definitions.Interface_Integer := 256 ; O_TRUNC : constant Interface_Definitions.Interface_Integer := 512 ; -- -- These constants define values used to specify the type of access desired -- when opening a file. -- type Strings_List is array (Positive range <>) of String_Pointer ; -- -- This type is the Ada representation of an array of C strings. This type -- is used by the function execvp to specify the argument list available to -- the new process. -- type Process_ID is new Interface_Integer ; -- -- This type is used to identify processes in the system. Each process in -- the system has its unique process ID. -- type Time_Value is record TV_Sec : Interface_Integer ; TV_Usec : Interface_Integer ; end record ; -- -- This type is used to keep track of time by the system. -- type Rusage_Record is record User_Time : Time_Value ; System_Time : Time_Value ; Ru_Maxrss : Interface_Integer ; Ru_Ixrss : Interface_Integer ; Ru_Idrss : Interface_Integer ; Ru_Isrss : Interface_Integer ; Ru_Minflt : Interface_Integer ; Ru_Majflt : Interface_Integer ; Ru_Nswap : Interface_Integer ; Ru_Inblock : Interface_Integer ; Ru_Oublock : Interface_Integer ; Ru_Msgsnd : Interface_Integer ; Ru_Msgrcv : Interface_Integer ; Ru_Nsignals : Interface_Integer ; Ru_Nwcsw : Interface_Integer ; Ru_Nivcsw : Interface_Integer ; end record ; -- -- This type defines a structure which is used by the function execvp -- to specify the resources used by a process. -- subtype Rusage_Record_Link is System.Address ; -- -- This type defines a reference to an Rusage_Record. -- type Status_Type is new Interface_Integer ; -- -- This type is used to return a status from a "Wait" operation. -- subtype Status_Type_Link is System.Address ; -- -- This type defines a reference to a Status_Type. -- W_No_Hang : constant := 1 ; -- -- This constant is used to specify an option when executing a process. -- It specifies for the parent process not to hang while waiting for a process. -- -------------------------------------------------------------------------------- -- File subprograms. -------------------------------------------------------------------------------- function Mkdir ( Path : in String_Pointer ; Mode : in Interface_Integer ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Mkdir -- -- This function creates a new directory. Path names the -- new directory. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Mkdir ) ; function Unlink ( Path : in String_Pointer ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Unlink -- -- This function removes the directory entry specified by the -- Path parameter. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Unlink ) ; function Rmdir ( Path : in String_Pointer ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Rmdir -- -- This function removes the directory specified by the Path -- parameter. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Rmdir ) ; function Rename ( Frompath : in String_Pointer ; Topath : in String_Pointer ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Rename -- -- This function renames a directory or a regular file within -- a file system. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Rename ) ; function Open ( Path : in String_Pointer ; Oflag : in Interface_Integer ; Mode : in Interface_Integer ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Open -- -- This function opens a file descriptor for the file named by -- the parameter Path. The function returns a non-negative -- Interface_Integer as the file descriptor if the operation is -- successful. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Open ) ; function Read ( D : in Interface_Integer ; Buf : in String_Pointer ; Nbyte : in Interface_Unsigned ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Read -- -- This function reads a maximum amount of Nbyte bytes into the -- buffer given by Buf from the file identified by D. The -- function returns the number of actual bytes read which can be -- less than Nbyte. If the function returns a 0, the end of file -- has been reached on the file identified by D. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Read ) ; function Write ( D : in Interface_Integer ; Buf : in String_Pointer ; NBytes : in Interface_Unsigned ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Write -- -- This function writes to the file identified by D a number of -- Nbytes bytes from the buffer given by Buf. Upon successful -- completion, the function returns the number of bytes written -- to the file. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Write ) ; function Close ( Fildes : in Interface_Integer ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Close -- -- This function closes the file associated with the file -- descriptor given by Fildes. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Close ) ; function Stat ( Path : in String_Pointer ; Buf : in Stat_Structure_Link ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Stat -- -- This function obtains information about a file. The Path -- identifies the file. The information is returned in the -- buffer provided by Buf. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Stat ) ; function Opendir ( Dirname : in String_Pointer ) return Dir_Link ; -------------------------------------------------------------------------------- -- -- Opendir -- -- This function opens the directory designated by the parameter -- Dirname, associates a directory stream with it, and returns -- the directory stream. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Opendir ) ; function Readdir ( Dirp : in Dir ) return Directory_Entry_Link ; -------------------------------------------------------------------------------- -- -- Readdir -- -- This function returns a pointer to the next directory entry -- of the directory identified by Dirp. The function returns -- Null when it reaches the end of the directory. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Readdir ) ; function Closedir ( Dirp : in Dir_Link ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Closedir -- -- This function closes terminates the directory stream given -- by Dirp and closes the underlying file descriptor. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Closedir ) ; function File_Access ( Path : in String_Pointer ; Amode : in Interface_Integer ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- File_Access -- -- This function checks the accessibility of the file identified -- by Path. The function returns a 0 if the access specified by -- Amode is allowed on the file given by Path. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , File_Access ) ; pragma Linkname ( File_Access , "access" ) ; function Ttyname ( Fildes : in Interface_Integer ) return String_Pointer ; -------------------------------------------------------------------------------- -- -- Ttyname -- -- This function gets and returns the name of the terminal -- specified by Fildes. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Ttyname ) ; function Isatty ( Fildes : in Interface_Integer ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Isatty -- -- This function returns True if the device associated with the -- file descriptor given by the Fildes parameter is a terminal. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Isatty ) ; function Is_Regular ( File : in Interface_Ushort ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Is_Regular -- -- This function will return a non-zero value if the value -- given by File identifies a regular file. The function returns -- a zero otherwise. -- -- Note: This function interfaces to a C function which -- implements the IS_REG pseudo-function. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Is_Regular ) ; function Is_Dir ( File : in Interface_Ushort ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Is_Dir -- -- This function will return a non-zero value if the value -- given by File identifies a directory. The function returns -- a zero otherwise. -- -- Note: This function interfaces to a C function which -- implements the IS_DIR pseudo-function. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Is_Dir ) ; -------------------------------------------------------------------------------- -- Process subprograms. -------------------------------------------------------------------------------- function Fork return Process_ID ; -------------------------------------------------------------------------------- -- -- Fork -- -- This function creates a new process and returns the new -- process ID. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Fork ) ; function Execvp ( File : in String_Pointer ; Argv : in Strings_List ) return Interface_Integer ; -------------------------------------------------------------------------------- -- -- Execvp -- -- This function executes a new program in the calling process. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Execvp ) ; function Wait3 ( Status : in Status_Type_Link ; Options : in Interface_Integer ; Rusage : in Rusage_Record_Link ) return Process_ID ; -------------------------------------------------------------------------------- -- -- Wait3 -- -- This function waits for a child process to stop or terminate. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Wait3 ) ; function Getenv ( Name : in String_Pointer ) return String_Pointer ; -------------------------------------------------------------------------------- -- -- Getenv -- -- This function gets the value of the environment variable -- given by Name. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Getenv ) ; function Getlogin return String_Pointer ; -------------------------------------------------------------------------------- -- -- Getlogin -- -- This function gets and returns the user's login name. -- -- None. -- -- -------------------------------------------------------------------------------- pragma Interface ( C , Getlogin ) ; end Runtime_Support_Library ; --