Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / ada / g-os_lib.ads
blobfa094b088c77bb87ae2600afe3383afd65d0e22c
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-2005 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 grow
40 -- as new services are needed by various tools.
42 -- This package tends to use fairly low-level Ada in order to not bring in
43 -- large portions of the RTL. For example, functions return access to string
44 -- as part of avoiding functions returning unconstrained types.
46 -- Except where specifically noted, these routines are portable across all
47 -- 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 -----------------------
56 -- String Operations --
57 -----------------------
59 -- These are reexported from package Strings (which was introduced to
60 -- avoid different packages declarting different types unnecessarily).
61 -- See package GNAT.Strings for details.
63 subtype String_Access is Strings.String_Access;
65 function "=" (Left, Right : in String_Access) return Boolean
66 renames Strings."=";
68 procedure Free (X : in out String_Access) renames Strings.Free;
70 subtype String_List is Strings.String_List;
72 function "=" (Left, Right : in String_List) return Boolean
73 renames Strings."=";
75 function "&" (Left : String_Access; Right : String_Access)
76 return String_List renames Strings."&";
77 function "&" (Left : String_Access; Right : String_List)
78 return String_List renames Strings."&";
79 function "&" (Left : String_List; Right : String_Access)
80 return String_List renames Strings."&";
81 function "&" (Left : String_List; Right : String_List)
82 return String_List renames Strings."&";
84 subtype String_List_Access is Strings.String_List_Access;
86 function "=" (Left, Right : in String_List_Access) return Boolean
87 renames Strings."=";
89 procedure Free (Arg : in out String_List_Access)
90 renames Strings.Free;
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 that
131 -- these have Intrinsic convention, so for example it is not permissible
132 -- 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 of
150 -- I/O routines in the typical C library (these functions are not part of
151 -- the ANSI C standard, but are typically available in all systems). See
152 -- also package Interfaces.C_Streams for access to the stream level
153 -- routines.
155 -- Note on file names. If a file name is passed as type String in any of
156 -- the following specifications, then the name is a normal Ada string and
157 -- 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 descriptor.
193 -- File descriptor returned is Invalid_FD if file cannot be opened.
195 function Create_File
196 (Name : String;
197 Fmode : Mode) return File_Descriptor;
198 -- Creates new file with given name for writing, returning file descriptor
199 -- for subsequent use in Write calls. File descriptor returned is
200 -- Invalid_FD if file cannot be successfully created.
202 function Create_Output_Text_File (Name : String) return File_Descriptor;
203 -- Creates new text file with given name suitable to redirect standard
204 -- output, returning file descriptor. File descriptor returned is
205 -- Invalid_FD if file cannot be successfully created.
207 function Create_New_File
208 (Name : String;
209 Fmode : Mode) return File_Descriptor;
210 -- Create new file with given name for writing, returning file descriptor
211 -- for subsequent use in Write calls. This differs from Create_File in
212 -- that it fails if the file already exists. File descriptor returned is
213 -- Invalid_FD if the file exists or cannot be created.
215 Temp_File_Len : constant Integer := 12;
216 -- Length of name returned by Create_Temp_File call (GNAT-XXXXXX & NUL)
218 subtype Temp_File_Name is String (1 .. Temp_File_Len);
219 -- String subtype set by Create_Temp_File
221 procedure Create_Temp_File
222 (FD : out File_Descriptor;
223 Name : out Temp_File_Name);
224 -- Create and open for writing a temporary file in the current working
225 -- directory. The name of the file and the File Descriptor are returned.
226 -- The File Descriptor returned is Invalid_FD in the case of failure. No
227 -- mode parameter is provided. Since this is a temporary file, there is no
228 -- point in doing text translation on it.
230 -- On some OSes, the maximum number of temp files that can be created with
231 -- this procedure may be limited. When the maximum is reached, this
232 -- procedure returns Invalid_FD. On some OSes, there may be a race
233 -- condition between processes trying to create temp files at the same
234 -- 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, there is
242 -- no point in doing text translation on it. It is the responsibility of
243 -- the caller to deallocate the access value returned in Name.
245 -- This procedure will always succeed if the current working directory is
246 -- 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 create
249 -- 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 wants to
258 -- ignore any possible error (see above for error cases).
260 procedure Set_Close_On_Exec
261 (FD : File_Descriptor;
262 Close_On_Exec : Boolean;
263 Status : out Boolean);
264 -- When Close_On_Exec is True, mark FD to be closed automatically when new
265 -- program is executed by the calling process (i.e. prevent FD from being
266 -- inherited by child processes). When Close_On_Exec is False, mark FD to
267 -- not be closed on exec (i.e. allow it to be inherited). Status is False
268 -- if the operation could not be performed.
270 procedure Delete_File (Name : String; Success : out Boolean);
271 -- Deletes file. Success is set True or False indicating if the delete is
272 -- successful.
274 procedure Rename_File
275 (Old_Name : String;
276 New_Name : String;
277 Success : out Boolean);
278 -- Rename a file. Success is set True or False indicating if the rename is
279 -- successful or not.
281 -- The following defines the mode for the Copy_File procedure below. Note
282 -- that "time stamps and other file attributes" in the descriptions below
283 -- refers to the creation and last modification times, and also the file
284 -- access (read/write/execute) status flags.
286 type Copy_Mode is
287 (Copy,
288 -- Copy the file. It is an error if the target file already exists. The
289 -- time stamps and other file attributes are preserved in the copy.
291 Overwrite,
292 -- If the target file exists, the file is replaced otherwise the file
293 -- is just copied. The time stamps and other file attributes are
294 -- preserved in the copy.
296 Append);
297 -- If the target file exists, the contents of the source file is
298 -- appended at the end. Otherwise the source file is just copied. The
299 -- time stamps and other file attributes are are preserved if the
300 -- destination file does not exist.
302 type Attribute is
303 (Time_Stamps,
304 -- Copy time stamps from source file to target file. All other
305 -- attributes are set to normal default values for file creation.
307 Full,
308 -- All attributes are copied from the source file to the target file.
309 -- This includes the timestamps, and for example also includes
310 -- read/write/execute attributes in Unix systems.
312 None);
313 -- No attributes are copied. All attributes including the time stamp
314 -- values are set to normal default values for file creation.
316 -- Note: The default is Time_Stamps, which corresponds to the normal
317 -- default on Windows style systems. Full corresponds to the typical
318 -- effect of "cp -p" on Unix systems, and None corresponds to the typical
319 -- effect of "cp" on Unix systems.
321 -- Note: Time_Stamps and Full are not supported on VMS and VxWorks
323 procedure Copy_File
324 (Name : String;
325 Pathname : String;
326 Success : out Boolean;
327 Mode : Copy_Mode := Copy;
328 Preserve : Attribute := Time_Stamps);
329 -- Copy a file. Name must designate a single file (no wild cards allowed).
330 -- Pathname can be a filename or directory name. In the latter case Name
331 -- is copied into the directory preserving the same file name. Mode
332 -- defines the kind of copy, see above with the default being a normal
333 -- copy in which the target file must not already exist. Success is set to
334 -- True or False indicating if the copy is successful (depending on the
335 -- specified Mode).
337 -- Note: this procedure is only supported to a very limited extent on VMS.
338 -- The only supported mode is Overwrite, and the only supported value for
339 -- Preserve is None, resulting in the default action which for Overwrite
340 -- is to leave attributes unchanged. Furthermore, the copy only works for
341 -- simple text files.
343 procedure Copy_Time_Stamps (Source, Dest : String; Success : out Boolean);
344 -- Copy Source file time stamps (last modification and last access time
345 -- stamps) to Dest file. Source and Dest must be valid filenames,
346 -- furthermore Dest must be writable. Success will be set to True if the
347 -- operation was successful and False otherwise.
349 -- Note: this procedure is not supported on VMS and VxWorks. On these
350 -- platforms, Success is always set to False.
352 function Read
353 (FD : File_Descriptor;
354 A : System.Address;
355 N : Integer) return Integer;
356 -- Read N bytes to address A from file referenced by FD. Returned value is
357 -- count of bytes actually read, which can be less than N at EOF.
359 function Write
360 (FD : File_Descriptor;
361 A : System.Address;
362 N : Integer) return Integer;
363 -- Write N bytes from address A to file referenced by FD. The returned
364 -- value is the number of bytes written, which can be less than N if a
365 -- disk full condition was detected.
367 Seek_Cur : constant := 1;
368 Seek_End : constant := 2;
369 Seek_Set : constant := 0;
370 -- Used to indicate origin for Lseek call
372 procedure Lseek
373 (FD : File_Descriptor;
374 offset : Long_Integer;
375 origin : Integer);
376 pragma Import (C, Lseek, "__gnat_lseek");
377 -- Sets the current file pointer to the indicated offset value, relative
378 -- to the current position (origin = SEEK_CUR), end of file (origin =
379 -- SEEK_END), or start of file (origin = SEEK_SET).
381 function File_Length (FD : File_Descriptor) return Long_Integer;
382 pragma Import (C, File_Length, "__gnat_file_length");
383 -- Get length of file from file descriptor FD
385 function File_Time_Stamp (Name : String) return OS_Time;
386 -- Given the name of a file or directory, Name, obtains and returns the
387 -- time stamp. This function can be used for an unopened file. Returns
388 -- Invalid_Time is Name doesn't correspond to an existing file.
390 function File_Time_Stamp (FD : File_Descriptor) return OS_Time;
391 -- Get time stamp of file from file descriptor FD Returns Invalid_Time is
392 -- FD doesn't correspond to an existing file.
394 function Normalize_Pathname
395 (Name : String;
396 Directory : String := "";
397 Resolve_Links : Boolean := True;
398 Case_Sensitive : Boolean := True) return String;
399 -- Returns a file name as an absolute path name, resolving all relative
400 -- directories, and symbolic links. The parameter Directory is a fully
401 -- resolved path name for a directory, or the empty string (the default).
402 -- Name is the name of a file, which is either relative to the given
403 -- directory name, if Directory is non-null, or to the current working
404 -- directory if Directory is null. The result returned is the normalized
405 -- name of the file. For most cases, if two file names designate the same
406 -- file through different paths, Normalize_Pathname will return the same
407 -- canonical name in both cases. However, there are cases when this is not
408 -- true; for example, this is not true in Unix for two hard links
409 -- designating the same file.
411 -- On Windows, the returned path will start with a drive letter except
412 -- when Directory is not empty and does not include a drive letter. If
413 -- Directory is empty (the default) and Name is a relative path or an
414 -- absolute path without drive letter, the letter of the current drive
415 -- will start the returned path. If Case_Sensitive is True (the default),
416 -- then this drive letter will be forced to upper case ("C:\...").
418 -- If Resolve_Links is set to True, then the symbolic links, on systems
419 -- that support them, will be fully converted to the name of the file or
420 -- directory pointed to. This is slightly less efficient, since it
421 -- requires system calls.
423 -- If Name cannot be resolved or is null on entry (for example if there is
424 -- symbolic link circularity, e.g. A is a symbolic link for B, and B is a
425 -- symbolic link for A), then Normalize_Pathname returns an empty string.
427 -- In VMS, if Name follows the VMS syntax file specification, it is first
428 -- converted into Unix syntax. If the conversion fails, Normalize_Pathname
429 -- returns an empty string.
431 -- For case-sensitive file systems, the value of Case_Sensitive parameter
432 -- is ignored. For file systems that are not case-sensitive, such as
433 -- Windows and OpenVMS, if this parameter is set to False, then the file
434 -- and directory names are folded to lower case. This allows checking
435 -- whether two files are the same by applying this function to their names
436 -- and comparing the results. If Case_Sensitive is set to True, this
437 -- function does not change the casing of file and directory names.
439 function Is_Absolute_Path (Name : String) return Boolean;
440 -- Returns True if Name is an absolute path name, i.e. it designates a
441 -- file or directory absolutely rather than relative to another directory.
443 function Is_Regular_File (Name : String) return Boolean;
444 -- Determines if the given string, Name, is the name of an existing
445 -- regular file. Returns True if so, False otherwise. Name may be an
446 -- absolute path name or a relative path name, including a simple file
447 -- name. If it is a relative path name, it is relative to the current
448 -- working directory.
450 function Is_Directory (Name : String) return Boolean;
451 -- Determines if the given string, Name, is the name of a directory.
452 -- Returns True if so, False otherwise. Name may be an absolute path
453 -- name or a relative path name, including a simple file name. If it is
454 -- a relative path name, it is relative to the current working directory.
456 function Is_Readable_File (Name : String) return Boolean;
457 -- Determines if the given string, Name, is the name of an existing file
458 -- that is readable. Returns True if so, False otherwise. Note that this
459 -- function simply interrogates the file attributes (e.g. using the C
460 -- function stat), so it does not indicate a situation in which a file may
461 -- not actually be readable due to some other process having exclusive
462 -- access.
464 function Is_Writable_File (Name : String) return Boolean;
465 -- Determines if the given string, Name, is the name of an existing file
466 -- that is writable. Returns True if so, False otherwise. Note that this
467 -- function simply interrogates the file attributes (e.g. using the C
468 -- function stat), so it does not indicate a situation in which a file may
469 -- not actually be writeable due to some other process having exclusive
470 -- access.
472 function Is_Symbolic_Link (Name : String) return Boolean;
473 -- Determines if the given string, Name, is the path of a symbolic link on
474 -- systems that support it. Returns True if so, False if the path is not a
475 -- symbolic link or if the system does not support symbolic links.
477 -- A symbolic link is an indirect pointer to a file; its directory entry
478 -- contains the name of the file to which it is linked. Symbolic links may
479 -- span file systems and may refer to directories.
481 procedure Set_Writable (Name : String);
482 -- Change the permissions on the named file to make it writable
483 -- for its owner.
485 procedure Set_Read_Only (Name : String);
486 -- Change the permissions on the named file to make it non-writable
487 -- for its owner.
489 procedure Set_Executable (Name : String);
490 -- Change the permissions on the named file to make it executable
491 -- for its owner.
493 function Locate_Exec_On_Path
494 (Exec_Name : String) return String_Access;
495 -- Try to locate an executable whose name is given by Exec_Name in the
496 -- directories listed in the environment Path. If the Exec_Name doesn't
497 -- have the executable suffix, it will be appended before the search.
498 -- Otherwise works like Locate_Regular_File below.
500 -- Note that this function allocates some memory for the returned value.
501 -- This memory needs to be deallocated after use.
503 function Locate_Regular_File
504 (File_Name : String;
505 Path : String) return String_Access;
506 -- Try to locate a regular file whose name is given by File_Name in the
507 -- directories listed in Path. If a file is found, its full pathname is
508 -- returned; otherwise, a null pointer is returned. If the File_Name given
509 -- is an absolute pathname, then Locate_Regular_File just checks that the
510 -- file exists and is a regular file. Otherwise, if the File_Name given
511 -- includes directory information, Locate_Regular_File first checks if the
512 -- file exists relative to the current directory. If it does not, or if
513 -- the File_Name given is a simple file name, the Path argument is parsed
514 -- according to OS conventions, and for each directory in the Path a check
515 -- is made if File_Name is a relative pathname of a regular file from that
516 -- directory.
518 -- Note that this function allocates some memory for the returned value.
519 -- This memory needs to be deallocated after use.
521 function Get_Debuggable_Suffix return String_Access;
522 -- Return the debuggable suffix convention. Usually this is the same as
523 -- the convention for Get_Executable_Suffix. The result is allocated on
524 -- the heap and should be freed when no longer needed to avoid storage
525 -- leaks.
527 function Get_Executable_Suffix return String_Access;
528 -- Return the executable suffix convention. The result is allocated on
529 -- the heap and should be freed when no longer needed to avoid storage
530 -- leaks.
532 function Get_Object_Suffix return String_Access;
533 -- Return the object suffix convention. The result is allocated on the
534 -- heap and should be freed when no longer needed to avoid storage leaks.
536 -- The following section contains low-level routines using addresses to
537 -- pass file name and executable name. In each routine the name must be
538 -- Nul-Terminated. For complete documentation refer to the equivalent
539 -- routine (using String in place of C_File_Name) defined above.
541 subtype C_File_Name is System.Address;
542 -- This subtype is used to document that a parameter is the address of a
543 -- null-terminated string containing the name of a file.
545 -- All the following functions need comments ???
547 function Open_Read
548 (Name : C_File_Name;
549 Fmode : Mode) return File_Descriptor;
551 function Open_Read_Write
552 (Name : C_File_Name;
553 Fmode : Mode) return File_Descriptor;
555 function Create_File
556 (Name : C_File_Name;
557 Fmode : Mode) return File_Descriptor;
559 function Create_New_File
560 (Name : C_File_Name;
561 Fmode : Mode) return File_Descriptor;
563 procedure Delete_File (Name : C_File_Name; Success : out Boolean);
565 procedure Rename_File
566 (Old_Name : C_File_Name;
567 New_Name : C_File_Name;
568 Success : out Boolean);
570 procedure Copy_File
571 (Name : C_File_Name;
572 Pathname : C_File_Name;
573 Success : out Boolean;
574 Mode : Copy_Mode := Copy;
575 Preserve : Attribute := Time_Stamps);
577 procedure Copy_Time_Stamps
578 (Source, Dest : C_File_Name;
579 Success : out Boolean);
581 function File_Time_Stamp (Name : C_File_Name) return OS_Time;
582 -- Returns Invalid_Time is Name doesn't correspond to an existing file
584 function Is_Regular_File (Name : C_File_Name) return Boolean;
585 function Is_Directory (Name : C_File_Name) return Boolean;
586 function Is_Readable_File (Name : C_File_Name) return Boolean;
587 function Is_Writable_File (Name : C_File_Name) return Boolean;
588 function Is_Symbolic_Link (Name : C_File_Name) return Boolean;
590 function Locate_Regular_File
591 (File_Name : C_File_Name;
592 Path : C_File_Name)
593 return String_Access;
595 ------------------
596 -- Subprocesses --
597 ------------------
599 subtype Argument_List is String_List;
600 -- Type used for argument list in call to Spawn. The lower bound of the
601 -- array should be 1, and the length of the array indicates the number of
602 -- arguments.
604 subtype Argument_List_Access is String_List_Access;
605 -- Type used to return Argument_List without dragging in secondary stack.
606 -- Note that there is a Free procedure declared for this subtype which
607 -- frees the array and all referenced strings.
609 procedure Normalize_Arguments (Args : in out Argument_List);
610 -- Normalize all arguments in the list. This ensure that the argument list
611 -- is compatible with the running OS and will works fine with Spawn and
612 -- Non_Blocking_Spawn for example. If Normalize_Arguments is called twice
613 -- on the same list it will do nothing the second time. Note that Spawn
614 -- and Non_Blocking_Spawn call Normalize_Arguments automatically, but
615 -- since there is a guarantee that a second call does nothing, this
616 -- internal call will have no effect if Normalize_Arguments is called
617 -- before calling Spawn. The call to Normalize_Arguments assumes that the
618 -- individual referenced arguments in Argument_List are on the heap, and
619 -- may free them and reallocate if they are modified.
621 procedure Spawn
622 (Program_Name : String;
623 Args : Argument_List;
624 Success : out Boolean);
625 -- This procedure spawns a program with a given list of arguments. The
626 -- first parameter of is the name of the executable. The second parameter
627 -- contains the arguments to be passed to this program. Success is False
628 -- if the named program could not be spawned or its execution completed
629 -- unsuccessfully. Note that the caller will be blocked until the
630 -- execution of the spawned program is complete. For maximum portability,
631 -- use a full path name for the Program_Name argument. On some systems
632 -- (notably Unix systems) a simple file name may also work (if the
633 -- executable can be located in the path).
635 -- "Spawn" should not be used in tasking applications. Why not??? More
636 -- documentation would be helpful here ??? Is it really tasking programs,
637 -- or tasking activity that cause trouble ???
639 -- Note: Arguments in Args that contain spaces and/or quotes such as
640 -- "--GCC=gcc -v" or "--GCC=""gcc -v""" are not portable across all
641 -- operating systems, and would not have the desired effect if they were
642 -- passed directly to the operating system. To avoid this problem, Spawn
643 -- makes an internal call to Normalize_Arguments, which ensures that such
644 -- arguments are modified in a manner that ensures that the desired effect
645 -- is obtained on all operating systems. The caller may call
646 -- Normalize_Arguments explicitly before the call (e.g. to print out the
647 -- exact form of arguments passed to the operating system). In this case
648 -- the guarantee a second call to Normalize_Arguments has no effect
649 -- ensures that the internal call will not affect the result. Note that
650 -- the implicit call to Normalize_Arguments may free and reallocate some
651 -- of the individual arguments.
653 -- This function will always set Success to False under VxWorks and other
654 -- similar operating systems which have no notion of the concept of
655 -- dynamically executable file.
657 function Spawn
658 (Program_Name : String;
659 Args : Argument_List)
660 return Integer;
661 -- Similar to the above procedure, but returns the actual status returned
662 -- by the operating system, or -1 under VxWorks and any other similar
663 -- operating systems which have no notion of separately spawnable programs.
665 -- "Spawn" should not be used in tasking applications.
667 procedure Spawn
668 (Program_Name : String;
669 Args : Argument_List;
670 Output_File_Descriptor : File_Descriptor;
671 Return_Code : out Integer;
672 Err_To_Out : Boolean := True);
673 -- Similar to the procedure above, but redirects the output to the file
674 -- designated by Output_File_Descriptor. If Err_To_Out is True, then the
675 -- Standard Error output is also redirected.
676 -- Return_Code is set to the status code returned by the operating system
678 -- "Spawn" should not be used in tasking applications.
680 procedure Spawn
681 (Program_Name : String;
682 Args : Argument_List;
683 Output_File : String;
684 Success : out Boolean;
685 Return_Code : out Integer;
686 Err_To_Out : Boolean := True);
687 -- Similar to the procedure above, but saves the output of the command to
688 -- a file with the name Output_File.
690 -- Success is set to True if the command is executed and its output
691 -- successfully written to the file. If Success is True, then Return_Code
692 -- will be set to the status code returned by the operating system.
693 -- Otherwise, Return_Code is undefined.
695 -- "Spawn" should not be used in tasking applications.
697 type Process_Id is private;
698 -- A private type used to identify a process activated by the following
699 -- non-blocking call. The only meaningful operation on this type is a
700 -- comparison for equality.
702 Invalid_Pid : constant Process_Id;
703 -- A special value used to indicate errors, as described below
705 function Non_Blocking_Spawn
706 (Program_Name : String;
707 Args : Argument_List)
708 return Process_Id;
709 -- This is a non blocking call. The Process_Id of the spawned process is
710 -- returned. Parameters are to be used as in Spawn. If Invalid_Id is
711 -- returned the program could not be spawned.
713 -- "Non_Blocking_Spawn" should not be used in tasking applications.
715 -- This function will always return Invalid_Id under VxWorks, since there
716 -- is no notion of executables under this OS.
718 procedure Wait_Process (Pid : out Process_Id; Success : out Boolean);
719 -- Wait for the completion of any of the processes created by previous
720 -- calls to Non_Blocking_Spawn. The caller will be suspended until one of
721 -- these processes terminates (normally or abnormally). If any of these
722 -- subprocesses terminates prior to the call to Wait_Process (and has not
723 -- been returned by a previous call to Wait_Process), then the call to
724 -- Wait_Process is immediate. Pid identifies the process that has
725 -- terminated (matching the value returned from Non_Blocking_Spawn).
726 -- Success is set to True if this sub-process terminated successfully. If
727 -- Pid = Invalid_Id, there were no subprocesses left to wait on.
729 -- This function will always set success to False under VxWorks, since
730 -- there is no notion of executables under this OS.
732 function Argument_String_To_List
733 (Arg_String : String)
734 return Argument_List_Access;
735 -- Take a string that is a program and its arguments and parse it into an
736 -- Argument_List. Note that the result is allocated on the heap, and must
737 -- be freed by the programmer (when it is no longer needed) to avoid
738 -- memory leaks.
740 -------------------
741 -- Miscellaneous --
742 -------------------
744 function Getenv (Name : String) return String_Access;
745 -- Get the value of the environment variable. Returns an access to the
746 -- empty string if the environment variable does not exist or has an
747 -- explicit null value (in some operating systems these are distinct
748 -- cases, in others they are not; this interface abstracts away that
749 -- difference. The argument is allocated on the heap (even in the null
750 -- case), and needs to be freed explicitly when no longer needed to avoid
751 -- memory leaks.
753 procedure Setenv (Name : String; Value : String);
754 -- Set the value of the environment variable Name to Value. This call
755 -- modifies the current environment, but does not modify the parent
756 -- process environment. After a call to Setenv, Getenv (Name) will always
757 -- return a String_Access referencing the same String as Value. This is
758 -- true also for the null string case (the actual effect may be to either
759 -- set an explicit null as the value, or to remove the entry, this is
760 -- operating system dependent). Note that any following calls to Spawn
761 -- will pass an environment to the spawned process that includes the
762 -- changes made by Setenv calls. This procedure is not available on VMS.
764 procedure OS_Exit (Status : Integer);
765 pragma Import (C, OS_Exit, "__gnat_os_exit");
766 pragma No_Return (OS_Exit);
767 -- Exit to OS with given status code (program is terminated)
769 procedure OS_Abort;
770 pragma Import (C, OS_Abort, "abort");
771 pragma No_Return (OS_Abort);
772 -- Exit to OS signalling an abort (traceback or other appropriate
773 -- diagnostic information should be given if possible, or entry made to
774 -- the debugger if that is possible).
776 function Errno return Integer;
777 pragma Import (C, Errno, "__get_errno");
778 -- Return the task-safe last error number
780 procedure Set_Errno (Errno : Integer);
781 pragma Import (C, Set_Errno, "__set_errno");
782 -- Set the task-safe error number
784 Directory_Separator : constant Character;
785 -- The character that is used to separate parts of a pathname
787 Path_Separator : constant Character;
788 -- The character to separate paths in an environment variable value
790 private
791 pragma Import (C, Path_Separator, "__gnat_path_separator");
792 pragma Import (C, Directory_Separator, "__gnat_dir_separator");
794 type OS_Time is new Long_Integer;
795 -- Type used for timestamps in the compiler. This type is used to hold
796 -- time stamps, but may have a different representation than C's time_t.
797 -- This type needs to match the declaration of OS_Time in adaint.h.
799 -- Add pragma Inline statements for comparison operations on OS_Time. It
800 -- would actually be nice to use pragma Import (Intrinsic) here, but this
801 -- was not properly supported till GNAT 3.15a, so that would cause
802 -- bootstrap path problems. To be changed later ???
804 Invalid_Time : constant OS_Time := -1;
805 -- This value should match the return valud by __gnat_file_time_*
807 pragma Inline ("<");
808 pragma Inline (">");
809 pragma Inline ("<=");
810 pragma Inline (">=");
812 type Process_Id is new Integer;
813 Invalid_Pid : constant Process_Id := -1;
815 end GNAT.OS_Lib;