* builtins.def (BUILT_IN_STACK_ALLOC): Remove.
[official-gcc.git] / gcc / ada / g-os_lib.ads
blobbd4201fc5f7fbd2ba79b699c3aaa2651f353c885
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T . O S _ L I B --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1995-2004 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
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.
49 with System;
50 with GNAT.Strings;
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
62 renames Strings."=";
64 procedure Free (X : in out String_Access) renames Strings.Free;
65 -- This procedure is provided for freeing returned values of type
66 -- String_Access
68 subtype String_List is Strings.String_List;
69 function "=" (Left, Right : in String_List) return Boolean
70 renames Strings."=";
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
84 renames Strings."=";
86 procedure Free (Arg : in out String_List_Access)
87 renames Strings.Free;
88 -- Frees the given array and all strings that its elements reference,
89 -- and then sets the argument to null. Provided for freeing returned
90 -- values of this type (including Argument_List_Access).
92 ---------------------
93 -- Time/Date Stuff --
94 ---------------------
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.
134 procedure GM_Split
135 (Date : OS_Time;
136 Year : out Year_Type;
137 Month : out Month_Type;
138 Day : out Day_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.
145 ----------------
146 -- File Stuff --
147 ----------------
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.
183 function Open_Read
184 (Name : String;
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
190 (Name : String;
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
194 -- opened.
196 function Create_File
197 (Name : String;
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
209 (Name : String;
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
244 -- returned in Name.
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
262 -- successful.
264 procedure Rename_File
265 (Old_Name : String;
266 New_Name : String;
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.
276 type Copy_Mode is
277 (Copy,
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.
281 Overwrite,
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.
286 Append);
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.
292 type Attribute is
293 (Time_Stamps,
294 -- Copy time stamps from source file to target file. All other
295 -- attributes are set to normal default values for file creation.
297 Full,
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.
302 None);
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
313 procedure Copy_File
314 (Name : String;
315 Pathname : String;
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.
342 function Read
343 (FD : File_Descriptor;
344 A : System.Address;
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.
349 function Write
350 (FD : File_Descriptor;
351 A : System.Address;
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
362 procedure Lseek
363 (FD : File_Descriptor;
364 offset : Long_Integer;
365 origin : 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
385 (Name : String;
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 -- If Resolve_Links is set to True, then the symbolic links, on systems
402 -- that support them, will be fully converted to the name of the file
403 -- or directory pointed to. This is slightly less efficient, since it
404 -- requires system calls.
406 -- If Name cannot be resolved or is null on entry (for example if there is
407 -- a circularity in symbolic links: A is a symbolic link for B, while B is
408 -- a symbolic link for A), then Normalize_Pathname returns an empty string.
410 -- In VMS, if Name follows the VMS syntax file specification, it is first
411 -- converted into Unix syntax. If the conversion fails, Normalize_Pathname
412 -- returns an empty string.
414 -- For case-sensitive file systems, the value of Case_Sensitive parameter
415 -- is ignored. In systems that have a non case-sensitive file system like
416 -- Windows and OpenVMS, if this parameter is set OFF, then the result
417 -- is returned folded to lower case, this allows to checks if two files
418 -- are the same by applying this function to their names and by comparing
419 -- the results of these calls. If Case_Sensitive is ON, this function does
420 -- not change the casing of file and directory names.
422 function Is_Absolute_Path (Name : String) return Boolean;
423 -- Returns True if Name is an absolute path name, i.e. it designates
424 -- a file or a directory absolutely, rather than relative to another
425 -- directory.
427 function Is_Regular_File (Name : String) return Boolean;
428 -- Determines if the given string, Name, is the name of an existing
429 -- regular file. Returns True if so, False otherwise. Name may be an
430 -- absolute path name or a relative path name, including a simple file
431 -- name. If it is a relative path name, it is relative to the current
432 -- working directory.
434 function Is_Directory (Name : String) return Boolean;
435 -- Determines if the given string, Name, is the name of a directory.
436 -- Returns True if so, False otherwise. Name may be an absolute path
437 -- name or a relative path name, including a simple file name. If it is
438 -- a relative path name, it is relative to the current working directory.
440 function Is_Readable_File (Name : String) return Boolean;
441 -- Determines if the given string, Name, is the name of an existing
442 -- file that is readable. Returns True if so, False otherwise. Note
443 -- that this function simply interrogates the file attributes (e.g.
444 -- using the C function stat), so it does not indicate a situation
445 -- in which a file may not actually be readable due to some other
446 -- process having exclusive access.
448 function Is_Writable_File (Name : String) return Boolean;
449 -- Determines if the given string, Name, is the name of an existing
450 -- file that is writable. 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 writeable due to some other
454 -- process having exclusive access.
456 function Is_Symbolic_Link (Name : String) return Boolean;
457 -- Determines if the given string, Name, is the path of a symbolic link
458 -- on systems that support it. Returns True if so, False if the path
459 -- is not a symbolic link or if the system does not support symbolic links.
461 -- A symbolic link is an indirect pointer to a file; its directory entry
462 -- contains the name of the file to which it is linked. Symbolic links may
463 -- span file systems and may refer to directories.
465 function Locate_Exec_On_Path
466 (Exec_Name : String) return String_Access;
467 -- Try to locate an executable whose name is given by Exec_Name in the
468 -- directories listed in the environment Path. If the Exec_Name doesn't
469 -- have the executable suffix, it will be appended before the search.
470 -- Otherwise works like Locate_Regular_File below.
472 -- Note that this function allocates some memory for the returned value.
473 -- This memory needs to be deallocated after use.
475 function Locate_Regular_File
476 (File_Name : String;
477 Path : String) return String_Access;
478 -- Try to locate a regular file whose name is given by File_Name in the
479 -- directories listed in Path. If a file is found, its full pathname is
480 -- returned; otherwise, a null pointer is returned. If the File_Name given
481 -- is an absolute pathname, then Locate_Regular_File just checks that the
482 -- file exists and is a regular file. Otherwise, if the File_Name given
483 -- includes directory information, Locate_Regular_File first checks if
484 -- the file exists relative to the current directory. If it does not,
485 -- or if the File_Name given is a simple file name, the Path argument is
486 -- parsed according to OS conventions, and for each directory in the Path
487 -- a check is made if File_Name is a relative pathname of a regular file
488 -- from that directory.
490 -- Note that this function allocates some memory for the returned value.
491 -- This memory needs to be deallocated after use.
493 function Get_Debuggable_Suffix return String_Access;
494 -- Return the debuggable suffix convention. Usually this is the same as
495 -- the convention for Get_Executable_Suffix. The result is allocated on
496 -- the heap and should be freed when no longer needed to avoid storage
497 -- leaks.
499 function Get_Executable_Suffix return String_Access;
500 -- Return the executable suffix convention. The result is allocated on
501 -- the heap and should be freed when no longer needed to avoid storage
502 -- leaks.
504 function Get_Object_Suffix return String_Access;
505 -- Return the object suffix convention. The result is allocated on the
506 -- heap and should be freed when no longer needed to avoid storage leaks.
508 -- The following section contains low-level routines using addresses to
509 -- pass file name and executable name. In each routine the name must be
510 -- Nul-Terminated. For complete documentation refer to the equivalent
511 -- routine (using String in place of C_File_Name) defined above.
513 subtype C_File_Name is System.Address;
514 -- This subtype is used to document that a parameter is the address
515 -- of a null-terminated string containing the name of a file.
517 -- All the following functions need comments ???
519 function Open_Read
520 (Name : C_File_Name;
521 Fmode : Mode) return File_Descriptor;
523 function Open_Read_Write
524 (Name : C_File_Name;
525 Fmode : Mode) return File_Descriptor;
527 function Create_File
528 (Name : C_File_Name;
529 Fmode : Mode) return File_Descriptor;
531 function Create_New_File
532 (Name : C_File_Name;
533 Fmode : Mode) return File_Descriptor;
535 procedure Delete_File (Name : C_File_Name; Success : out Boolean);
537 procedure Rename_File
538 (Old_Name : C_File_Name;
539 New_Name : C_File_Name;
540 Success : out Boolean);
542 procedure Copy_File
543 (Name : C_File_Name;
544 Pathname : C_File_Name;
545 Success : out Boolean;
546 Mode : Copy_Mode := Copy;
547 Preserve : Attribute := Time_Stamps);
549 procedure Copy_Time_Stamps
550 (Source, Dest : C_File_Name;
551 Success : out Boolean);
553 function File_Time_Stamp (Name : C_File_Name) return OS_Time;
554 -- Returns Invalid_Time is Name doesn't correspond to an existing file.
556 function Is_Regular_File (Name : C_File_Name) return Boolean;
558 function Is_Directory (Name : C_File_Name) return Boolean;
560 function Is_Readable_File (Name : C_File_Name) return Boolean;
561 function Is_Writable_File (Name : C_File_Name) return Boolean;
562 function Is_Symbolic_Link (Name : C_File_Name) return Boolean;
564 function Locate_Regular_File
565 (File_Name : C_File_Name;
566 Path : C_File_Name)
567 return String_Access;
569 ------------------
570 -- Subprocesses --
571 ------------------
573 subtype Argument_List is String_List;
574 -- Type used for argument list in call to Spawn. The lower bound
575 -- of the array should be 1, and the length of the array indicates
576 -- the number of arguments.
578 subtype Argument_List_Access is String_List_Access;
579 -- Type used to return Argument_List without dragging in secondary stack.
580 -- Note that there is a Free procedure declared for this subtype which
581 -- frees the array and all referenced strings.
583 procedure Normalize_Arguments (Args : in out Argument_List);
584 -- Normalize all arguments in the list. This ensure that the argument list
585 -- is compatible with the running OS and will works fine with Spawn and
586 -- Non_Blocking_Spawn for example. If Normalize_Arguments is called twice
587 -- on the same list it will do nothing the second time. Note that Spawn
588 -- and Non_Blocking_Spawn call Normalize_Arguments automatically, but
589 -- since there is a guarantee that a second call does nothing, this
590 -- internal call will have no effect if Normalize_Arguments is called
591 -- before calling Spawn. The call to Normalize_Arguments assumes that
592 -- the individual referenced arguments in Argument_List are on the heap,
593 -- and may free them and reallocate if they are modified.
595 procedure Spawn
596 (Program_Name : String;
597 Args : Argument_List;
598 Success : out Boolean);
599 -- The first parameter of function Spawn is the name of the executable.
600 -- The second parameter contains the arguments to be passed to the
601 -- program. Success is False if the named program could not be spawned
602 -- or its execution completed unsuccessfully. Note that the caller will
603 -- be blocked until the execution of the spawned program is complete.
604 -- For maximum portability, use a full path name for the Program_Name
605 -- argument. On some systems (notably Unix systems) a simple file
606 -- name may also work (if the executable can be located in the path).
608 -- "Spawn" should not be used in tasking applications.
610 -- Note: Arguments in Args that contain spaces and/or quotes such as
611 -- "--GCC=gcc -v" or "--GCC=""gcc -v""" are not portable across all
612 -- operating systems, and would not have the desired effect if they
613 -- were passed directly to the operating system. To avoid this problem,
614 -- Spawn makes an internal call to Normalize_Arguments, which ensures
615 -- that such arguments are modified in a manner that ensures that the
616 -- desired effect is obtained on all operating systems. The caller may
617 -- call Normalize_Arguments explicitly before the call (e.g. to print
618 -- out the exact form of arguments passed to the operating system). In
619 -- this case the guarantee a second call to Normalize_Arguments has no
620 -- effect ensures that the internal call will not affect the result.
621 -- Note that the implicit call to Normalize_Arguments may free and
622 -- reallocate some of the individual arguments.
624 -- This function will always set Success to False under VxWorks and
625 -- other similar operating systems which have no notion of the concept
626 -- of a dynamically executable file.
628 function Spawn
629 (Program_Name : String;
630 Args : Argument_List)
631 return Integer;
632 -- Similar to the above procedure, but returns the actual status returned
633 -- by the operating system, or -1 under VxWorks and any other similar
634 -- operating systems which have no notion of separately spawnable programs.
636 -- "Spawn" should not be used in tasking applications.
639 type Process_Id is private;
640 -- A private type used to identify a process activated by the following
641 -- non-blocking call. The only meaningful operation on this type is a
642 -- comparison for equality.
644 Invalid_Pid : constant Process_Id;
645 -- A special value used to indicate errors, as described below.
647 function Non_Blocking_Spawn
648 (Program_Name : String;
649 Args : Argument_List)
650 return Process_Id;
651 -- This is a non blocking call. The Process_Id of the spawned process
652 -- is returned. Parameters are to be used as in Spawn. If Invalid_Id
653 -- is returned the program could not be spawned.
655 -- "Non_Blocking_Spawn" should not be used in tasking applications.
657 -- This function will always return Invalid_Id under VxWorks, since
658 -- there is no notion of executables under this OS.
660 procedure Wait_Process (Pid : out Process_Id; Success : out Boolean);
661 -- Wait for the completion of any of the processes created by previous
662 -- calls to Non_Blocking_Spawn. The caller will be suspended until one
663 -- of these processes terminates (normally or abnormally). If any of
664 -- these subprocesses terminates prior to the call to Wait_Process (and
665 -- has not been returned by a previous call to Wait_Process), then the
666 -- call to Wait_Process is immediate. Pid identifies the process that
667 -- has terminated (matching the value returned from Non_Blocking_Spawn).
668 -- Success is set to True if this sub-process terminated successfully.
669 -- If Pid = Invalid_Id, there were no subprocesses left to wait on.
671 -- This function will always set success to False under VxWorks, since
672 -- there is no notion of executables under this OS.
674 function Argument_String_To_List
675 (Arg_String : String)
676 return Argument_List_Access;
677 -- Take a string that is a program and its arguments and parse it into
678 -- an Argument_List. Note that the result is allocated on the heap, and
679 -- must be freed by the programmer (when it is no longer needed) to avoid
680 -- memory leaks.
682 -------------------
683 -- Miscellaneous --
684 -------------------
686 function Getenv (Name : String) return String_Access;
687 -- Get the value of the environment variable. Returns an access
688 -- to the empty string if the environment variable does not exist
689 -- or has an explicit null value (in some operating systems these
690 -- are distinct cases, in others they are not; this interface
691 -- abstracts away that difference. The argument is allocated on
692 -- the heap (even in the null case), and needs to be freed explicitly
693 -- when no longer needed to avoid memory leaks.
695 procedure Setenv (Name : String; Value : String);
696 -- Set the value of the environment variable Name to Value. This call
697 -- modifies the current environment, but does not modify the parent
698 -- process environment. After a call to Setenv, Getenv (Name) will
699 -- always return a String_Access referencing the same String as Value.
700 -- This is true also for the null string case (the actual effect may
701 -- be to either set an explicit null as the value, or to remove the
702 -- entry, this is operating system dependent). Note that any following
703 -- calls to Spawn will pass an environment to the spawned process that
704 -- includes the changes made by Setenv calls. This procedure is not
705 -- available under VMS.
707 procedure OS_Exit (Status : Integer);
708 pragma Import (C, OS_Exit, "__gnat_os_exit");
709 pragma No_Return (OS_Exit);
710 -- Exit to OS with given status code (program is terminated)
712 procedure OS_Abort;
713 pragma Import (C, OS_Abort, "abort");
714 pragma No_Return (OS_Abort);
715 -- Exit to OS signalling an abort (traceback or other appropriate
716 -- diagnostic information should be given if possible, or entry made
717 -- to the debugger if that is possible).
719 function Errno return Integer;
720 pragma Import (C, Errno, "__get_errno");
721 -- Return the task-safe last error number.
723 procedure Set_Errno (Errno : Integer);
724 pragma Import (C, Set_Errno, "__set_errno");
725 -- Set the task-safe error number.
727 Directory_Separator : constant Character;
728 -- The character that is used to separate parts of a pathname.
730 Path_Separator : constant Character;
731 -- The character to separate paths in an environment variable value.
733 private
734 pragma Import (C, Path_Separator, "__gnat_path_separator");
735 pragma Import (C, Directory_Separator, "__gnat_dir_separator");
737 type OS_Time is new Long_Integer;
738 -- Type used for timestamps in the compiler. This type is used to
739 -- hold time stamps, but may have a different representation than
740 -- C's time_t. This type needs to match the declaration of OS_Time
741 -- in adaint.h.
743 -- Add pragma Inline statements for comparison operations on OS_Time.
744 -- It would actually be nice to use pragma Import (Intrinsic) here,
745 -- but this was not properly supported till GNAT 3.15a, so that would
746 -- cause bootstrap path problems. To be changed later ???
748 Invalid_Time : constant OS_Time := -1;
749 -- This value should match the return valud by __gnat_file_time_*
751 pragma Inline ("<");
752 pragma Inline (">");
753 pragma Inline ("<=");
754 pragma Inline (">=");
756 type Process_Id is new Integer;
757 Invalid_Pid : constant Process_Id := -1;
759 end GNAT.OS_Lib;