OSDN Git Service

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