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