OSDN Git Service

* adaint.h, adaint.c
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-os_lib.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                          G N A T . O S _ L I B                           --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1995-2004 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  Operating system interface facilities
35
36 --  This package contains types and procedures for interfacing to the
37 --  underlying OS. It is used by the GNAT compiler and by tools associated
38 --  with the GNAT compiler, and therefore works for the various operating
39 --  systems to which GNAT has been ported. This package will undoubtedly
40 --  grow as new services are needed by various tools.
41
42 --  This package tends to use fairly low-level Ada in order to not bring
43 --  in large portions of the RTL. For example, functions return access
44 --  to string as part of avoiding functions returning unconstrained types.
45
46 --  Except where specifically noted, these routines are portable across
47 --  all GNAT implementations on all supported operating systems.
48
49 with System;
50 with GNAT.Strings;
51
52 package GNAT.OS_Lib is
53 pragma Elaborate_Body (OS_Lib);
54
55    subtype String_Access is Strings.String_Access;
56    --  General purpose string access type. Some of the functions in this
57    --  package allocate string results on the heap, and return a value of
58    --  this type. Note that the caller is responsible for freeing this
59    --  String to avoid memory leaks.
60
61    function "=" (Left, Right : in String_Access) return Boolean
62      renames Strings."=";
63
64    procedure Free (X : in out String_Access) renames Strings.Free;
65    --  This procedure is provided for freeing returned values of type
66    --  String_Access
67
68    subtype String_List is Strings.String_List;
69    function "=" (Left, Right : in String_List) return Boolean
70      renames Strings."=";
71
72    function "&" (Left : String_Access; Right : String_Access)
73      return String_List renames Strings."&";
74    function "&" (Left : String_Access; Right : String_List)
75      return String_List renames Strings."&";
76    function "&" (Left : String_List; Right : String_Access)
77      return String_List renames Strings."&";
78    function "&" (Left : String_List; Right : String_List)
79      return String_List renames Strings."&";
80
81    subtype String_List_Access is Strings.String_List_Access;
82    --  General purpose array and pointer for list of string accesses
83    function "=" (Left, Right : in String_List_Access) return Boolean
84      renames Strings."=";
85
86    procedure Free (Arg : in out String_List_Access)
87      renames Strings.Free;
88    --  Frees the given array and all strings that its elements reference,
89    --  and then sets the argument to null. Provided for freeing returned
90    --  values of this type (including Argument_List_Access).
91
92    ---------------------
93    -- Time/Date Stuff --
94    ---------------------
95
96    type OS_Time is private;
97    --  The OS's notion of time is represented by the private type OS_Time.
98    --  This is the type returned by the File_Time_Stamp functions to obtain
99    --  the time stamp of a specified file. Functions and a procedure (modeled
100    --  after the similar subprograms in package Calendar) are provided for
101    --  extracting information from a value of this type. Although these are
102    --  called GM, the intention is not that they provide GMT times in all
103    --  cases but rather the actual (time-zone independent) time stamp of the
104    --  file (of course in Unix systems, this *is* in GMT form).
105
106    Invalid_Time : constant OS_Time;
107    --  A special unique value used to flag an invalid time stamp value
108
109    subtype Year_Type   is Integer range 1900 .. 2099;
110    subtype Month_Type  is Integer range    1 ..   12;
111    subtype Day_Type    is Integer range    1 ..   31;
112    subtype Hour_Type   is Integer range    0 ..   23;
113    subtype Minute_Type is Integer range    0 ..   59;
114    subtype Second_Type is Integer range    0 ..   59;
115    --  Declarations similar to those in Calendar, breaking down the time
116
117
118    function GM_Year    (Date : OS_Time) return Year_Type;
119    function GM_Month   (Date : OS_Time) return Month_Type;
120    function GM_Day     (Date : OS_Time) return Day_Type;
121    function GM_Hour    (Date : OS_Time) return Hour_Type;
122    function GM_Minute  (Date : OS_Time) return Minute_Type;
123    function GM_Second  (Date : OS_Time) return Second_Type;
124    --  Functions to extract information from OS_Time value
125
126    function "<"  (X, Y : OS_Time) return Boolean;
127    function ">"  (X, Y : OS_Time) return Boolean;
128    function ">=" (X, Y : OS_Time) return Boolean;
129    function "<=" (X, Y : OS_Time) return Boolean;
130    --  Basic comparison operators on OS_Time with obvious meanings. Note
131    --  that these have Intrinsic convention, so for example it is not
132    --  permissible to create accesses to any of these functions.
133
134    procedure GM_Split
135      (Date    : OS_Time;
136       Year    : out Year_Type;
137       Month   : out Month_Type;
138       Day     : out Day_Type;
139       Hour    : out Hour_Type;
140       Minute  : out Minute_Type;
141       Second  : out Second_Type);
142    --  Analogous to the routine of similar name in Calendar, takes an OS_Time
143    --  and splits it into its component parts with obvious meanings.
144
145    ----------------
146    -- File Stuff --
147    ----------------
148
149    --  These routines give access to the open/creat/close/read/write level
150    --  of I/O routines in the typical C library (these functions are not
151    --  part of the ANSI C standard, but are typically available in all
152    --  systems). See also package Interfaces.C_Streams for access to the
153    --  stream level routines.
154
155    --  Note on file names. If a file name is passed as type String in any
156    --  of the following specifications, then the name is a normal Ada string
157    --  and need not be NUL-terminated. However, a trailing NUL character is
158    --  permitted, and will be ignored (more accurately, the NUL and any
159    --  characters that follow it will be ignored).
160
161    type File_Descriptor is new Integer;
162    --  Corresponds to the int file handle values used in the C routines
163
164    Standin  : constant File_Descriptor := 0;
165    Standout : constant File_Descriptor := 1;
166    Standerr : constant File_Descriptor := 2;
167    --  File descriptors for standard input output files
168
169    Invalid_FD : constant File_Descriptor := -1;
170    --  File descriptor returned when error in opening/creating file;
171
172    type Mode is (Binary, Text);
173    for Mode'Size use Integer'Size;
174    for Mode use (Binary => 0, Text => 1);
175    --  Used in all the Open and Create calls to specify if the file is to be
176    --  opened in binary mode or text mode. In systems like Unix, this has no
177    --  effect, but in systems capable of text mode translation, the use of
178    --  Text as the mode parameter causes the system to do CR/LF translation
179    --  and also to recognize the DOS end of file character on input. The use
180    --  of Text where appropriate allows programs to take a portable Unix view
181    --  of DOS-format files and process them appropriately.
182
183    function Open_Read
184      (Name  : String;
185       Fmode : Mode) return File_Descriptor;
186    --  Open file Name for reading, returning file descriptor File descriptor
187    --  returned is Invalid_FD if file cannot be opened.
188
189    function Open_Read_Write
190      (Name  : String;
191       Fmode : Mode) return File_Descriptor;
192    --  Open file Name for both reading and writing, returning file
193    --  descriptor. File descriptor returned is Invalid_FD if file cannot be
194    --  opened.
195
196    function Create_File
197      (Name  : String;
198       Fmode : Mode) return File_Descriptor;
199    --  Creates new file with given name for writing, returning file descriptor
200    --  for subsequent use in Write calls. File descriptor returned is
201    --  Invalid_FD if file cannot be successfully created.
202
203    function Create_Output_Text_File (Name  : String) return File_Descriptor;
204    --  Creates new text file with given name suitable to redirect standard
205    --  output, returning file descriptor. File descriptor returned is
206    --  Invalid_FD if file cannot be successfully created.
207
208    function Create_New_File
209      (Name  : String;
210       Fmode : Mode) return File_Descriptor;
211    --  Create new file with given name for writing, returning file descriptor
212    --  for subsequent use in Write calls. This differs from Create_File in
213    --  that it fails if the file already exists. File descriptor returned is
214    --  Invalid_FD if the file exists or cannot be created.
215
216    Temp_File_Len : constant Integer := 12;
217    --  Length of name returned by Create_Temp_File call (GNAT-XXXXXX & NUL)
218
219    subtype Temp_File_Name is String (1 .. Temp_File_Len);
220    --  String subtype set by Create_Temp_File
221
222    procedure Create_Temp_File
223      (FD   : out File_Descriptor;
224       Name : out Temp_File_Name);
225    --  Create and open for writing a temporary file in the current working
226    --  directory. The name of the file and the File Descriptor are returned.
227    --  The File Descriptor returned is Invalid_FD in the case of failure.
228    --  No mode parameter is provided. Since this is a temporary file,
229    --  there is no point in doing text translation on it.
230    --  On some OSes, the maximum number of temp files that can be
231    --  created with this procedure may be limited. When the maximum is
232    --  reached, this procedure returns Invalid_FD. On some OSes, there may be
233    --  a race condition between processes trying to create temp files
234    --  at the same time in the same directory using this procedure.
235
236    procedure Create_Temp_File
237      (FD   : out File_Descriptor;
238       Name : out String_Access);
239    --  Create and open for writing a temporary file in the current working
240    --  directory. The name of the file and the File Descriptor are returned.
241    --  No mode parameter is provided. Since this is a temporary file,
242    --  there is no point in doing text translation on it.
243    --  It is the responsibility of the caller to deallocate the access value
244    --  returned in Name.
245    --  This procedure will always succeed if the current working directory
246    --  is writable. If the current working directory is not writable, then
247    --  Invalid_FD is returned for the file descriptor and null for the Name.
248    --  There is no race condition problem between processes trying to
249    --  create temp files at the same time in the same directory.
250
251    procedure Close (FD : File_Descriptor; Status : out Boolean);
252    --  Close file referenced by FD. Status is False if the underlying service
253    --  failed. Reasons for failure include: disk full, disk quotas exceeded
254    --  and invalid file descriptor (the file may have been closed twice).
255
256    procedure Close (FD : File_Descriptor);
257    --  Close file referenced by FD. This form is used when the caller
258    --  wants to ignore any possible error (see above for error cases).
259
260    procedure Delete_File (Name : String; Success : out Boolean);
261    --  Deletes file. Success is set True or False indicating if the delete is
262    --  successful.
263
264    procedure Rename_File
265      (Old_Name : String;
266       New_Name : String;
267       Success  : out Boolean);
268    --  Rename a file. Success is set True or False indicating if the
269    --  rename is successful or not.
270
271    --  The following defines the mode for the Copy_File procedure below.
272    --  Note that "time stamps and other file attributes" in the descriptions
273    --  below refers to the creation and last modification times, and also
274    --  the file access (read/write/execute) status flags.
275
276    type Copy_Mode is
277      (Copy,
278       --  Copy the file. It is an error if the target file already exists.
279       --  The time stamps and other file attributes are preserved in the copy.
280
281       Overwrite,
282       --  If the target file exists, the file is replaced otherwise
283       --  the file is just copied. The time stamps and other file
284       --  attributes are preserved in the copy.
285
286       Append);
287       --  If the target file exists, the contents of the source file
288       --  is appended at the end. Otherwise the source file is just
289       --  copied. The time stamps and other file attributes are
290       --  are preserved if the destination file does not exist.
291
292    type Attribute is
293      (Time_Stamps,
294       --  Copy time stamps from source file to target file. All other
295       --  attributes are set to normal default values for file creation.
296
297       Full,
298       --  All attributes are copied from the source file to the target
299       --  file. This includes the timestamps, and for example also includes
300       --  read/write/execute attributes in Unix systems.
301
302       None);
303       --  No attributes are copied. All attributes including the time stamp
304       --  values are set to normal default values for file creation.
305
306    --  Note: The default is Time_Stamps, which corresponds to the normal
307    --  default on Windows style systems. Full corresponds to the typical
308    --  effect of "cp -p" on Unix systems, and None corresponds to the
309    --  typical effect of "cp" on Unix systems.
310
311    --  Note: Time_Stamps and Full are not supported on VMS and VxWorks
312
313    procedure Copy_File
314      (Name     : String;
315       Pathname : String;
316       Success  : out Boolean;
317       Mode     : Copy_Mode := Copy;
318       Preserve : Attribute := Time_Stamps);
319    --  Copy a file. Name must designate a single file (no wild cards allowed).
320    --  Pathname can be a filename or directory name. In the latter case Name
321    --  is copied into the directory preserving the same file name. Mode
322    --  defines the kind of copy, see above with the default being a normal
323    --  copy in which the target file must not already exist. Success is set
324    --  to True or False indicating if the copy is successful (depending on
325    --  the specified Mode).
326    --
327    --  Note: this procedure is only supported to a very limited extent on
328    --  VMS. The only supported mode is Overwrite, and the only supported
329    --  value for Preserve is None, resulting in the default action which
330    --  for Overwrite is to leave attributes unchanged. Furthermore, the
331    --  copy only works for simple text files.
332
333    procedure Copy_Time_Stamps (Source, Dest : String; Success : out Boolean);
334    --  Copy Source file time stamps (last modification and last access time
335    --  stamps) to Dest file. Source and Dest must be valid filenames,
336    --  furthermore Dest must be writable. Success will be set to True if the
337    --  operation was successful and False otherwise.
338    --
339    --  Note: this procedure is not supported on VMS and VxWorks. On these
340    --  platforms, Success is always set to False.
341
342    function Read
343      (FD   : File_Descriptor;
344       A    : System.Address;
345       N    : Integer) return Integer;
346    --  Read N bytes to address A from file referenced by FD. Returned value
347    --  is count of bytes actually read, which can be less than N at EOF.
348
349    function Write
350      (FD   : File_Descriptor;
351       A    : System.Address;
352       N    : Integer) return Integer;
353    --  Write N bytes from address A to file referenced by FD. The returned
354    --  value is the number of bytes written, which can be less than N if
355    --  a disk full condition was detected.
356
357    Seek_Cur : constant := 1;
358    Seek_End : constant := 2;
359    Seek_Set : constant := 0;
360    --  Used to indicate origin for Lseek call
361
362    procedure Lseek
363      (FD     : File_Descriptor;
364       offset : Long_Integer;
365       origin : Integer);
366    pragma Import (C, Lseek, "__gnat_lseek");
367    --  Sets the current file pointer to the indicated offset value,
368    --  relative to the current position (origin = SEEK_CUR), end of
369    --  file (origin = SEEK_END), or start of file (origin = SEEK_SET).
370
371    function File_Length (FD : File_Descriptor) return Long_Integer;
372    pragma Import (C, File_Length, "__gnat_file_length");
373    --  Get length of file from file descriptor FD
374
375    function File_Time_Stamp (Name : String) return OS_Time;
376    --  Given the name of a file or directory, Name, obtains and returns the
377    --  time stamp. This function can be used for an unopened file.
378    --  Returns Invalid_Time is Name doesn't correspond to an existing file.
379
380    function File_Time_Stamp (FD : File_Descriptor) return OS_Time;
381    --  Get time stamp of file from file descriptor FD
382    --  Returns Invalid_Time is FD doesn't correspond to an existing file.
383
384    function Normalize_Pathname
385      (Name           : String;
386       Directory      : String  := "";
387       Resolve_Links  : Boolean := True;
388       Case_Sensitive : Boolean := True) return String;
389    --  Returns a file name as an absolute path name, resolving all relative
390    --  directories, and symbolic links. The parameter Directory is a fully
391    --  resolved path name for a directory, or the empty string (the default).
392    --  Name is the name of a file, which is either relative to the given
393    --  directory name, if Directory is non-null, or to the current working
394    --  directory if Directory is null. The result returned is the normalized
395    --  name of the file. For most cases, if two file names designate the same
396    --  file through different paths, Normalize_Pathname will return the same
397    --  canonical name in both cases. However, there are cases when this is
398    --  not true; for example, this is not true in Unix for two hard links
399    --  designating the same file.
400    --
401    --  On Windows, the returned path will start with a drive letter except
402    --  when Directory is not empty and does not include a drive letter.
403    --  If Directory is empty (the default) and Name is a relative path
404    --  or an absolute path without drive letter, the letter of the current
405    --  drive will start the returned path. If Case_Sensitive is True
406    --  (the default), then this drive letter will be forced to upper case
407    --  ("C:\...").
408    --
409    --  If Resolve_Links is set to True, then the symbolic links, on systems
410    --  that support them, will be fully converted to the name of the file
411    --  or directory pointed to. This is slightly less efficient, since it
412    --  requires system calls.
413    --
414    --  If Name cannot be resolved or is null on entry (for example if there is
415    --  a circularity in symbolic links: A is a symbolic link for B, while B is
416    --  a symbolic link for A), then Normalize_Pathname returns an empty string.
417    --
418    --  In VMS, if Name follows the VMS syntax file specification, it is first
419    --  converted into Unix syntax. If the conversion fails, Normalize_Pathname
420    --  returns an empty string.
421    --
422    --  For case-sensitive file systems, the value of Case_Sensitive parameter
423    --  is ignored.  For file systems that are not case-sensitive, such as
424    --  Windows and OpenVMS, if this parameter is set to False, then the file
425    --  and directory names are folded to lower case. This allows checking
426    --  whether two files are the same by applying this function to their names
427    --  and comparing the results.  If Case_Sensitive is set to True, this
428    --  function does not change the casing of file and directory names.
429
430    function Is_Absolute_Path (Name : String) return Boolean;
431    --  Returns True if Name is an absolute path name, i.e. it designates
432    --  a file or a directory absolutely, rather than relative to another
433    --  directory.
434
435    function Is_Regular_File (Name : String) return Boolean;
436    --  Determines if the given string, Name, is the name of an existing
437    --  regular file. Returns True if so, False otherwise. Name may be an
438    --  absolute path name or a relative path name, including a simple file
439    --  name. If it is a relative path name, it is relative to the current
440    --  working directory.
441
442    function Is_Directory (Name : String) return Boolean;
443    --  Determines if the given string, Name, is the name of a directory.
444    --  Returns True if so, False otherwise. Name may be an absolute path
445    --  name or a relative path name, including a simple file name. If it is
446    --  a relative path name, it is relative to the current working directory.
447
448    function Is_Readable_File (Name : String) return Boolean;
449    --  Determines if the given string, Name, is the name of an existing
450    --  file that is readable. Returns True if so, False otherwise. Note
451    --  that this function simply interrogates the file attributes (e.g.
452    --  using the C function stat), so it does not indicate a situation
453    --  in which a file may not actually be readable due to some other
454    --  process having exclusive access.
455
456    function Is_Writable_File (Name : String) return Boolean;
457    --  Determines if the given string, Name, is the name of an existing
458    --  file that is writable. Returns True if so, False otherwise. Note
459    --  that this function simply interrogates the file attributes (e.g.
460    --  using the C function stat), so it does not indicate a situation
461    --  in which a file may not actually be writeable due to some other
462    --  process having exclusive access.
463
464    function Is_Symbolic_Link (Name : String) return Boolean;
465    --  Determines if the given string, Name, is the path of a symbolic link
466    --  on systems that support it. Returns True if so, False if the path
467    --  is not a symbolic link or if the system does not support symbolic links.
468    --
469    --  A symbolic link is an indirect pointer to a file; its directory entry
470    --  contains the name of the file to which it is linked. Symbolic links may
471    --  span file systems and may refer to directories.
472
473    procedure Set_Writable (Name : String);
474    --  Change the permissions on the named file to make it writable
475    --  for its owner.
476
477    procedure Set_Read_Only (Name : String);
478    --  Change the permissions on the named file to make it non-writable
479    --  for its owner.
480
481    procedure Set_Executable (Name : String);
482    --  Change the permissions on the named file to make it executable
483    --  for its owner.
484
485    function Locate_Exec_On_Path
486      (Exec_Name : String) return String_Access;
487    --  Try to locate an executable whose name is given by Exec_Name in the
488    --  directories listed in the environment Path. If the Exec_Name doesn't
489    --  have the executable suffix, it will be appended before the search.
490    --  Otherwise works like Locate_Regular_File below.
491    --
492    --  Note that this function allocates some memory for the returned value.
493    --  This memory needs to be deallocated after use.
494
495    function Locate_Regular_File
496      (File_Name : String;
497       Path      : String) return String_Access;
498    --  Try to locate a regular file whose name is given by File_Name in the
499    --  directories listed in  Path. If a file is found, its full pathname is
500    --  returned; otherwise, a null pointer is returned. If the File_Name given
501    --  is an absolute pathname, then Locate_Regular_File just checks that the
502    --  file exists and is a regular file. Otherwise, if the File_Name given
503    --  includes directory information, Locate_Regular_File first checks if
504    --  the file exists relative to the current directory. If it does not,
505    --  or if the File_Name given is a simple file name, the Path argument is
506    --  parsed according to OS conventions, and for each directory in the Path
507    --  a check is made if File_Name is a relative pathname of a regular file
508    --  from that directory.
509    --
510    --  Note that this function allocates some memory for the returned value.
511    --  This memory needs to be deallocated after use.
512
513    function Get_Debuggable_Suffix return String_Access;
514    --  Return the debuggable suffix convention. Usually this is the same as
515    --  the convention for Get_Executable_Suffix. The result is allocated on
516    --  the heap and should be freed when no longer needed to avoid storage
517    --  leaks.
518
519    function Get_Executable_Suffix return String_Access;
520    --  Return the executable suffix convention. The result is allocated on
521    --  the heap and should be freed when no longer needed to avoid storage
522    --  leaks.
523
524    function Get_Object_Suffix return String_Access;
525    --  Return the object suffix convention. The result is allocated on the
526    --  heap and should be freed when no longer needed to avoid storage leaks.
527
528    --  The following section contains low-level routines using addresses to
529    --  pass file name and executable name. In each routine the name must be
530    --  Nul-Terminated. For complete documentation refer to the equivalent
531    --  routine (using String in place of C_File_Name) defined above.
532
533    subtype C_File_Name is System.Address;
534    --  This subtype is used to document that a parameter is the address
535    --  of a null-terminated string containing the name of a file.
536
537    --  All the following functions need comments ???
538
539    function Open_Read
540      (Name  : C_File_Name;
541       Fmode : Mode) return File_Descriptor;
542
543    function Open_Read_Write
544      (Name  : C_File_Name;
545       Fmode : Mode) return File_Descriptor;
546
547    function Create_File
548      (Name  : C_File_Name;
549       Fmode : Mode) return File_Descriptor;
550
551    function Create_New_File
552      (Name  : C_File_Name;
553       Fmode : Mode) return File_Descriptor;
554
555    procedure Delete_File (Name : C_File_Name; Success : out Boolean);
556
557    procedure Rename_File
558      (Old_Name : C_File_Name;
559       New_Name : C_File_Name;
560       Success  : out Boolean);
561
562    procedure Copy_File
563      (Name     : C_File_Name;
564       Pathname : C_File_Name;
565       Success  : out Boolean;
566       Mode     : Copy_Mode := Copy;
567       Preserve : Attribute := Time_Stamps);
568
569    procedure Copy_Time_Stamps
570      (Source, Dest : C_File_Name;
571       Success      : out Boolean);
572
573    function File_Time_Stamp (Name : C_File_Name) return OS_Time;
574    --  Returns Invalid_Time is Name doesn't correspond to an existing file.
575
576    function Is_Regular_File (Name : C_File_Name) return Boolean;
577    function Is_Directory (Name : C_File_Name) return Boolean;
578    function Is_Readable_File (Name : C_File_Name) return Boolean;
579    function Is_Writable_File (Name : C_File_Name) return Boolean;
580    function Is_Symbolic_Link (Name : C_File_Name) return Boolean;
581
582    function Locate_Regular_File
583      (File_Name : C_File_Name;
584       Path      : C_File_Name)
585       return      String_Access;
586
587    ------------------
588    -- Subprocesses --
589    ------------------
590
591    subtype Argument_List is String_List;
592    --  Type used for argument list in call to Spawn. The lower bound
593    --  of the array should be 1, and the length of the array indicates
594    --  the number of arguments.
595
596    subtype Argument_List_Access is String_List_Access;
597    --  Type used to return Argument_List without dragging in secondary stack.
598    --  Note that there is a Free procedure declared for this subtype which
599    --  frees the array and all referenced strings.
600
601    procedure Normalize_Arguments (Args : in out Argument_List);
602    --  Normalize all arguments in the list. This ensure that the argument list
603    --  is compatible with the running OS and will works fine with Spawn and
604    --  Non_Blocking_Spawn for example. If Normalize_Arguments is called twice
605    --  on the same list it will do nothing the second time. Note that Spawn
606    --  and Non_Blocking_Spawn call Normalize_Arguments automatically, but
607    --  since there is a guarantee that a second call does nothing, this
608    --  internal call will have no effect if Normalize_Arguments is called
609    --  before calling Spawn. The call to Normalize_Arguments assumes that
610    --  the individual referenced arguments in Argument_List are on the heap,
611    --  and may free them and reallocate if they are modified.
612
613    procedure Spawn
614      (Program_Name : String;
615       Args         : Argument_List;
616       Success      : out Boolean);
617    --  The first parameter of function Spawn is the name of the executable.
618    --  The second parameter contains the arguments to be passed to the
619    --  program. Success is False if the named program could not be spawned
620    --  or its execution completed unsuccessfully. Note that the caller will
621    --  be blocked until the execution of the spawned program is complete.
622    --  For maximum portability, use a full path name for the Program_Name
623    --  argument. On some systems (notably Unix systems) a simple file
624    --  name may also work (if the executable can be located in the path).
625    --
626    --  "Spawn" should not be used in tasking applications.
627    --
628    --  Note: Arguments in Args that contain spaces and/or quotes such as
629    --  "--GCC=gcc -v" or "--GCC=""gcc -v""" are not portable across all
630    --  operating systems, and would not have the desired effect if they
631    --  were passed directly to the operating system. To avoid this problem,
632    --  Spawn makes an internal call to Normalize_Arguments, which ensures
633    --  that such arguments are modified in a manner that ensures that the
634    --  desired effect is obtained on all operating systems. The caller may
635    --  call Normalize_Arguments explicitly before the call (e.g. to print
636    --  out the exact form of arguments passed to the operating system). In
637    --  this case the guarantee a second call to Normalize_Arguments has no
638    --  effect ensures that the internal call will not affect the result.
639    --  Note that the implicit call to Normalize_Arguments may free and
640    --  reallocate some of the individual arguments.
641    --
642    --  This function will always set Success to False under VxWorks and
643    --  other similar operating systems which have no notion of the concept
644    --  of a dynamically executable file.
645
646    function Spawn
647      (Program_Name : String;
648       Args         : Argument_List)
649       return         Integer;
650    --  Similar to the above procedure, but returns the actual status returned
651    --  by the operating system, or -1 under VxWorks and any other similar
652    --  operating systems which have no notion of separately spawnable programs.
653    --
654    --  "Spawn" should not be used in tasking applications.
655
656    procedure Spawn
657      (Program_Name           : String;
658       Args                   : Argument_List;
659       Output_File_Descriptor : File_Descriptor;
660       Return_Code            : out Integer;
661       Err_To_Out             : Boolean := True);
662    --  Similar to the procedure above, but redirects the output to
663    --  the file designated by Output_File_Descriptor. If Err_To_Out
664    --  is True, then the Standard Error output is also redirected.
665    --
666    --  Return_Code is set to the status code returned by the operating
667    --  system as described above.
668    --
669    --  "Spawn" should not be used in tasking applications.
670
671    procedure Spawn
672      (Program_Name  : String;
673       Args          : Argument_List;
674       Output_File   : String;
675       Success       : out Boolean;
676       Return_Code   : out Integer;
677       Err_To_Out    : Boolean := True);
678    --  Similar to the procedure above, but saves the output of the command
679    --  to a file with the name Output_File.
680    --
681    --  Success is set to True if the command is executed and its output
682    --  successfully written to the file. If Success is True, then
683    --  Return_Code will be set to the status code returned by the
684    --  operating system. Otherwise, Return_Code is undefined.
685    --
686    --  "Spawn" should not be used in tasking applications.
687
688    type Process_Id is private;
689    --  A private type used to identify a process activated by the following
690    --  non-blocking call. The only meaningful operation on this type is a
691    --  comparison for equality.
692
693    Invalid_Pid : constant Process_Id;
694    --  A special value used to indicate errors, as described below.
695
696    function Non_Blocking_Spawn
697      (Program_Name : String;
698       Args         : Argument_List)
699       return         Process_Id;
700    --  This is a non blocking call. The Process_Id of the spawned process
701    --  is returned. Parameters are to be used as in Spawn. If Invalid_Id
702    --  is returned the program could not be spawned.
703    --
704    --  "Non_Blocking_Spawn" should not be used in tasking applications.
705    --
706    --  This function will always return Invalid_Id under VxWorks, since
707    --  there is no notion of executables under this OS.
708
709    procedure Wait_Process (Pid : out Process_Id; Success : out Boolean);
710    --  Wait for the completion of any of the processes created by previous
711    --  calls to Non_Blocking_Spawn. The caller will be suspended until one
712    --  of these processes terminates (normally or abnormally). If any of
713    --  these subprocesses terminates prior to the call to Wait_Process (and
714    --  has not been returned by a previous call to Wait_Process), then the
715    --  call to Wait_Process is immediate. Pid identifies the process that
716    --  has terminated (matching the value returned from Non_Blocking_Spawn).
717    --  Success is set to True if this sub-process terminated successfully.
718    --  If Pid = Invalid_Id, there were no subprocesses left to wait on.
719    --
720    --  This function will always set success to False under VxWorks, since
721    --  there is no notion of executables under this OS.
722
723    function Argument_String_To_List
724      (Arg_String : String)
725       return       Argument_List_Access;
726    --  Take a string that is a program and its arguments and parse it into
727    --  an Argument_List. Note that the result is allocated on the heap, and
728    --  must be freed by the programmer (when it is no longer needed) to avoid
729    --  memory leaks.
730
731    -------------------
732    -- Miscellaneous --
733    -------------------
734
735    function Getenv (Name : String) return String_Access;
736    --  Get the value of the environment variable. Returns an access
737    --  to the empty string if the environment variable does not exist
738    --  or has an explicit null value (in some operating systems these
739    --  are distinct cases, in others they are not; this interface
740    --  abstracts away that difference. The argument is allocated on
741    --  the heap (even in the null case), and needs to be freed explicitly
742    --  when no longer needed to avoid memory leaks.
743
744    procedure Setenv (Name : String; Value : String);
745    --  Set the value of the environment variable Name to Value. This call
746    --  modifies the current environment, but does not modify the parent
747    --  process environment. After a call to Setenv, Getenv (Name) will
748    --  always return a String_Access referencing the same String as Value.
749    --  This is true also for the null string case (the actual effect may
750    --  be to either set an explicit null as the value, or to remove the
751    --  entry, this is operating system dependent). Note that any following
752    --  calls to Spawn will pass an environment to the spawned process that
753    --  includes the changes made by Setenv calls. This procedure is not
754    --  available under VMS.
755
756    procedure OS_Exit (Status : Integer);
757    pragma Import (C, OS_Exit, "__gnat_os_exit");
758    pragma No_Return (OS_Exit);
759    --  Exit to OS with given status code (program is terminated)
760
761    procedure OS_Abort;
762    pragma Import (C, OS_Abort, "abort");
763    pragma No_Return (OS_Abort);
764    --  Exit to OS signalling an abort (traceback or other appropriate
765    --  diagnostic information should be given if possible, or entry made
766    --  to the debugger if that is possible).
767
768    function Errno return Integer;
769    pragma Import (C, Errno, "__get_errno");
770    --  Return the task-safe last error number.
771
772    procedure Set_Errno (Errno : Integer);
773    pragma Import (C, Set_Errno, "__set_errno");
774    --  Set the task-safe error number.
775
776    Directory_Separator : constant Character;
777    --  The character that is used to separate parts of a pathname.
778
779    Path_Separator : constant Character;
780    --  The character to separate paths in an environment variable value.
781
782 private
783    pragma Import (C, Path_Separator, "__gnat_path_separator");
784    pragma Import (C, Directory_Separator, "__gnat_dir_separator");
785
786    type OS_Time is new Long_Integer;
787    --  Type used for timestamps in the compiler. This type is used to
788    --  hold time stamps, but may have a different representation than
789    --  C's time_t. This type needs to match the declaration of OS_Time
790    --  in adaint.h.
791
792    --  Add pragma Inline statements for comparison operations on OS_Time.
793    --  It would actually be nice to use pragma Import (Intrinsic) here,
794    --  but this was not properly supported till GNAT 3.15a, so that would
795    --  cause bootstrap path problems. To be changed later ???
796
797    Invalid_Time : constant OS_Time := -1;
798    --  This value should match the return valud by __gnat_file_time_*
799
800    pragma Inline ("<");
801    pragma Inline (">");
802    pragma Inline ("<=");
803    pragma Inline (">=");
804
805    type Process_Id is new Integer;
806    Invalid_Pid : constant Process_Id := -1;
807
808 end GNAT.OS_Lib;