OSDN Git Service

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