1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . O S _ L I B --
9 -- Copyright (C) 1995-2003 Free Software Foundation, Inc. --
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. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- Operating system interface facilities
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.
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.
46 -- Except where specifically noted, these routines are portable across
47 -- all GNAT implementations on all supported operating systems.
52 package GNAT.OS_Lib is
53 pragma Elaborate_Body (OS_Lib);
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.
61 function "=" (Left, Right : in String_Access) return Boolean
64 procedure Free (X : in out String_Access) renames Strings.Free;
65 -- This procedure is provided for freeing returned values of type
68 subtype String_List is Strings.String_List;
69 function "=" (Left, Right : in String_List) return Boolean
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."&";
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
86 procedure Free (Arg : in out String_List_Access)
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).
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).
105 type OS_Time is private;
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;
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;
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.
131 Year : out Year_Type;
132 Month : out Month_Type;
134 Hour : out Hour_Type;
135 Minute : out Minute_Type;
136 Second : out Second_Type);
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.
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).
154 type File_Descriptor is new Integer;
155 -- Corresponds to the int file handle values used in the C routines
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
162 Invalid_FD : constant File_Descriptor := -1;
163 -- File descriptor returned when error in opening/creating file;
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.
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.
183 function Open_Read_Write
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
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
199 function Create_New_File
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.
208 Temp_File_Len : constant Integer := 12;
209 -- Length of name returned by Create_Temp_File call (GNAT-XXXXXX & NUL)
211 subtype Temp_File_Name is String (1 .. Temp_File_Len);
212 -- String subtype set by Create_Temp_File
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.
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
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.
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).
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).
252 procedure Delete_File (Name : String; Success : out Boolean);
253 -- Deletes file. Success is set True or False indicating if the delete is
256 procedure Rename_File
259 Success : out Boolean);
260 -- Rename a file. Success is set True or False indicating if the
261 -- rename is successful or not.
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.
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.
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.
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.
286 -- Copy time stamps from source file to target file. All other
287 -- attributes are set to normal default values for file creation.
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.
295 -- No attributes are copied. All attributes including the time stamp
296 -- values are set to normal default values for file creation.
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.
303 -- Note: Time_Stamps and Full are not supported on VMS and VxWorks
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).
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.
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.
331 -- Note: this procedure is not supported on VMS and VxWorks. On these
332 -- platforms, Success is always set to False.
335 (FD : File_Descriptor;
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.
344 (FD : File_Descriptor;
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.
353 Seek_Cur : constant := 1;
354 Seek_End : constant := 2;
355 Seek_Set : constant := 0;
356 -- Used to indicate origin for Lseek call
359 (FD : File_Descriptor;
360 offset : Long_Integer;
362 pragma Import (C, Lseek, "__gnat_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).
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
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.
375 function File_Time_Stamp (FD : File_Descriptor) return OS_Time;
376 -- Get time stamp of file from file descriptor FD
378 function Normalize_Pathname
380 Directory : String := "";
381 Resolve_Links : Boolean := True;
382 Case_Sensitive : Boolean := True)
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.
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.
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.
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.
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.
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 file or a directory absolutely, rather than relative to another
422 function Is_Regular_File (Name : String) return Boolean;
423 -- Determines if the given string, Name, is the name of an existing
424 -- regular file. Returns True if so, False otherwise. Name may be an
425 -- absolute path name or a relative path name, including a simple file
426 -- name. If it is a relative path name, it is relative to the current
427 -- working directory.
429 function Is_Directory (Name : String) return Boolean;
430 -- Determines if the given string, Name, is the name of a directory.
431 -- Returns True if so, False otherwise. Name may be an absolute path
432 -- name or a relative path name, including a simple file name. If it is
433 -- a relative path name, it is relative to the current working directory.
435 function Is_Readable_File (Name : String) return Boolean;
436 -- Determines if the given string, Name, is the name of an existing
437 -- file that is readable. Returns True if so, False otherwise. Note
438 -- that this function simply interrogates the file attributes (e.g.
439 -- using the C function stat), so it does not indicate a situation
440 -- in which a file may not actually be readable due to some other
441 -- process having exclusive access.
443 function Is_Writable_File (Name : String) return Boolean;
444 -- Determines if the given string, Name, is the name of an existing
445 -- file that is writable. Returns True if so, False otherwise. Note
446 -- that this function simply interrogates the file attributes (e.g.
447 -- using the C function stat), so it does not indicate a situation
448 -- in which a file may not actually be writeable due to some other
449 -- process having exclusive access.
451 function Is_Symbolic_Link (Name : String) return Boolean;
452 -- Determines if the given string, Name, is the path of a symbolic link
453 -- on systems that support it. Returns True if so, False if the path
454 -- is not a symbolic link or if the system does not support symbolic links.
456 -- A symbolic link is an indirect pointer to a file; its directory entry
457 -- contains the name of the file to which it is linked. Symbolic links may
458 -- span file systems and may refer to directories.
460 function Locate_Exec_On_Path
462 return String_Access;
463 -- Try to locate an executable whose name is given by Exec_Name in the
464 -- directories listed in the environment Path. If the Exec_Name doesn't
465 -- have the executable suffix, it will be appended before the search.
466 -- Otherwise works like Locate_Regular_File below.
468 -- Note that this function allocates some memory for the returned value.
469 -- This memory needs to be deallocated after use.
471 function Locate_Regular_File
474 return String_Access;
475 -- Try to locate a regular file whose name is given by File_Name in the
476 -- directories listed in Path. If a file is found, its full pathname is
477 -- returned; otherwise, a null pointer is returned. If the File_Name given
478 -- is an absolute pathname, then Locate_Regular_File just checks that the
479 -- file exists and is a regular file. Otherwise, if the File_Name given
480 -- includes directory information, Locate_Regular_File first checks if
481 -- the file exists relative to the current directory. If it does not,
482 -- or if the File_Name given is a simple file name, the Path argument is
483 -- parsed according to OS conventions, and for each directory in the Path
484 -- a check is made if File_Name is a relative pathname of a regular file
485 -- from that directory.
487 -- Note that this function allocates some memory for the returned value.
488 -- This memory needs to be deallocated after use.
490 function Get_Debuggable_Suffix return String_Access;
491 -- Return the debuggable suffix convention. Usually this is the same as
492 -- the convention for Get_Executable_Suffix. The result is allocated on
493 -- the heap and should be freed when no longer needed to avoid storage
496 function Get_Executable_Suffix return String_Access;
497 -- Return the executable suffix convention. The result is allocated on
498 -- the heap and should be freed when no longer needed to avoid storage
501 function Get_Object_Suffix return String_Access;
502 -- Return the object suffix convention. The result is allocated on the
503 -- heap and should be freed when no longer needed to avoid storage leaks.
505 -- The following section contains low-level routines using addresses to
506 -- pass file name and executable name. In each routine the name must be
507 -- Nul-Terminated. For complete documentation refer to the equivalent
508 -- routine (using String in place of C_File_Name) defined above.
510 subtype C_File_Name is System.Address;
511 -- This subtype is used to document that a parameter is the address
512 -- of a null-terminated string containing the name of a file.
517 return File_Descriptor;
519 function Open_Read_Write
522 return File_Descriptor;
527 return File_Descriptor;
529 function Create_New_File
532 return File_Descriptor;
534 procedure Delete_File (Name : C_File_Name; Success : out Boolean);
536 procedure Rename_File
537 (Old_Name : C_File_Name;
538 New_Name : C_File_Name;
539 Success : out Boolean);
543 Pathname : C_File_Name;
544 Success : out Boolean;
545 Mode : Copy_Mode := Copy;
546 Preserve : Attribute := Time_Stamps);
548 procedure Copy_Time_Stamps
549 (Source, Dest : C_File_Name;
550 Success : out Boolean);
552 function File_Time_Stamp (Name : C_File_Name) return OS_Time;
554 function Is_Regular_File (Name : C_File_Name) return Boolean;
556 function Is_Directory (Name : C_File_Name) return Boolean;
558 function Is_Readable_File (Name : C_File_Name) return Boolean;
559 function Is_Writable_File (Name : C_File_Name) return Boolean;
560 function Is_Symbolic_Link (Name : C_File_Name) return Boolean;
562 function Locate_Regular_File
563 (File_Name : C_File_Name;
565 return String_Access;
571 subtype Argument_List is String_List;
572 -- Type used for argument list in call to Spawn. The lower bound
573 -- of the array should be 1, and the length of the array indicates
574 -- the number of arguments.
576 subtype Argument_List_Access is String_List_Access;
577 -- Type used to return Argument_List without dragging in secondary stack.
578 -- Note that there is a Free procedure declared for this subtype which
579 -- frees the array and all referenced strings.
581 procedure Normalize_Arguments (Args : in out Argument_List);
582 -- Normalize all arguments in the list. This ensure that the argument list
583 -- is compatible with the running OS and will works fine with Spawn and
584 -- Non_Blocking_Spawn for example. If Normalize_Arguments is called twice
585 -- on the same list it will do nothing the second time. Note that Spawn
586 -- and Non_Blocking_Spawn call Normalize_Arguments automatically, but
587 -- since there is a guarantee that a second call does nothing, this
588 -- internal call will have no effect if Normalize_Arguments is called
589 -- before calling Spawn. The call to Normalize_Arguments assumes that
590 -- the individual referenced arguments in Argument_List are on the heap,
591 -- and may free them and reallocate if they are modified.
594 (Program_Name : String;
595 Args : Argument_List;
596 Success : out Boolean);
597 -- The first parameter of function Spawn is the name of the executable.
598 -- The second parameter contains the arguments to be passed to the
599 -- program. Success is False if the named program could not be spawned
600 -- or its execution completed unsuccessfully. Note that the caller will
601 -- be blocked until the execution of the spawned program is complete.
602 -- For maximum portability, use a full path name for the Program_Name
603 -- argument. On some systems (notably Unix systems) a simple file
604 -- name may also work (if the executable can be located in the path).
606 -- "Spawn" should not be used in tasking applications.
608 -- Note: Arguments in Args that contain spaces and/or quotes such as
609 -- "--GCC=gcc -v" or "--GCC=""gcc -v""" are not portable across all
610 -- operating systems, and would not have the desired effect if they
611 -- were passed directly to the operating system. To avoid this problem,
612 -- Spawn makes an internal call to Normalize_Arguments, which ensures
613 -- that such arguments are modified in a manner that ensures that the
614 -- desired effect is obtained on all operating systems. The caller may
615 -- call Normalize_Arguments explicitly before the call (e.g. to print
616 -- out the exact form of arguments passed to the operating system). In
617 -- this case the guarantee a second call to Normalize_Arguments has no
618 -- effect ensures that the internal call will not affect the result.
619 -- Note that the implicit call to Normalize_Arguments may free and
620 -- reallocate some of the individual arguments.
622 -- This function will always set Success to False under VxWorks and
623 -- other similar operating systems which have no notion of the concept
624 -- of a dynamically executable file.
627 (Program_Name : String;
628 Args : Argument_List)
630 -- Similar to the above procedure, but returns the actual status returned
631 -- by the operating system, or -1 under VxWorks and any other similar
632 -- operating systems which have no notion of separately spawnable programs.
634 -- "Spawn" should not be used in tasking applications.
637 type Process_Id is private;
638 -- A private type used to identify a process activated by the following
639 -- non-blocking call. The only meaningful operation on this type is a
640 -- comparison for equality.
642 Invalid_Pid : constant Process_Id;
643 -- A special value used to indicate errors, as described below.
645 function Non_Blocking_Spawn
646 (Program_Name : String;
647 Args : Argument_List)
649 -- This is a non blocking call. The Process_Id of the spawned process
650 -- is returned. Parameters are to be used as in Spawn. If Invalid_Id
651 -- is returned the program could not be spawned.
653 -- "Non_Blocking_Spawn" should not be used in tasking applications.
655 -- This function will always return Invalid_Id under VxWorks, since
656 -- there is no notion of executables under this OS.
658 procedure Wait_Process (Pid : out Process_Id; Success : out Boolean);
659 -- Wait for the completion of any of the processes created by previous
660 -- calls to Non_Blocking_Spawn. The caller will be suspended until one
661 -- of these processes terminates (normally or abnormally). If any of
662 -- these subprocesses terminates prior to the call to Wait_Process (and
663 -- has not been returned by a previous call to Wait_Process), then the
664 -- call to Wait_Process is immediate. Pid identifies the process that
665 -- has terminated (matching the value returned from Non_Blocking_Spawn).
666 -- Success is set to True if this sub-process terminated successfully.
667 -- If Pid = Invalid_Id, there were no subprocesses left to wait on.
669 -- This function will always set success to False under VxWorks, since
670 -- there is no notion of executables under this OS.
672 function Argument_String_To_List
673 (Arg_String : String)
674 return Argument_List_Access;
675 -- Take a string that is a program and its arguments and parse it into
676 -- an Argument_List. Note that the result is allocated on the heap, and
677 -- must be freed by the programmer (when it is no longer needed) to avoid
684 function Getenv (Name : String) return String_Access;
685 -- Get the value of the environment variable. Returns an access
686 -- to the empty string if the environment variable does not exist
687 -- or has an explicit null value (in some operating systems these
688 -- are distinct cases, in others they are not; this interface
689 -- abstracts away that difference. The argument is allocated on
690 -- the heap (even in the null case), and needs to be freed explicitly
691 -- when no longer needed to avoid memory leaks.
693 procedure Setenv (Name : String; Value : String);
694 -- Set the value of the environment variable Name to Value. This call
695 -- modifies the current environment, but does not modify the parent
696 -- process environment. After a call to Setenv, Getenv (Name) will
697 -- always return a String_Access referencing the same String as Value.
698 -- This is true also for the null string case (the actual effect may
699 -- be to either set an explicit null as the value, or to remove the
700 -- entry, this is operating system dependent). Note that any following
701 -- calls to Spawn will pass an environment to the spawned process that
702 -- includes the changes made by Setenv calls. This procedure is not
703 -- available under VMS.
705 procedure OS_Exit (Status : Integer);
706 pragma Import (C, OS_Exit, "__gnat_os_exit");
707 pragma No_Return (OS_Exit);
708 -- Exit to OS with given status code (program is terminated)
711 pragma Import (C, OS_Abort, "abort");
712 pragma No_Return (OS_Abort);
713 -- Exit to OS signalling an abort (traceback or other appropriate
714 -- diagnostic information should be given if possible, or entry made
715 -- to the debugger if that is possible).
717 function Errno return Integer;
718 pragma Import (C, Errno, "__get_errno");
719 -- Return the task-safe last error number.
721 procedure Set_Errno (Errno : Integer);
722 pragma Import (C, Set_Errno, "__set_errno");
723 -- Set the task-safe error number.
725 Directory_Separator : constant Character;
726 -- The character that is used to separate parts of a pathname.
728 Path_Separator : constant Character;
729 -- The character to separate paths in an environment variable value.
732 pragma Import (C, Path_Separator, "__gnat_path_separator");
733 pragma Import (C, Directory_Separator, "__gnat_dir_separator");
735 type OS_Time is new Long_Integer;
736 -- Type used for timestamps in the compiler. This type is used to
737 -- hold time stamps, but may have a different representation than
738 -- C's time_t. This type needs to match the declaration of OS_Time
741 -- Add pragma Inline statements for comparison operations on OS_Time.
742 -- It would actually be nice to use pragma Import (Intrinsic) here,
743 -- but this was not properly supported till GNAT 3.15a, so that would
744 -- cause bootstrap path problems. To be changed later ???
748 pragma Inline ("<=");
749 pragma Inline (">=");
751 type Process_Id is new Integer;
752 Invalid_Pid : constant Process_Id := -1;