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