OSDN Git Service

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