1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . C R T L --
9 -- Copyright (C) 2003-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 -- This package provides the low level interface to the C Run Time Library
33 -- on non-VMS systems.
35 with System
.Parameters
;
37 package System
.CRTL
is
40 subtype chars
is System
.Address
;
41 -- Pointer to null-terminated array of characters
43 subtype DIRs
is System
.Address
;
44 -- Corresponds to the C type DIR*
46 subtype FILEs
is System
.Address
;
47 -- Corresponds to the C type FILE*
49 subtype int
is Integer;
51 type long
is range -(2 ** (System
.Parameters
.long_bits
- 1))
52 .. +(2 ** (System
.Parameters
.long_bits
- 1)) - 1;
54 subtype off_t
is Long_Integer;
56 type size_t
is mod 2 ** Standard
'Address_Size;
58 type Filename_Encoding
is (UTF8
, ASCII_8bits
, Unspecified
);
59 for Filename_Encoding
use (UTF8
=> 0, ASCII_8bits
=> 1, Unspecified
=> 2);
60 pragma Convention
(C
, Filename_Encoding
);
61 -- Describes the filename's encoding
63 function atoi
(A
: System
.Address
) return Integer;
64 pragma Import
(C
, atoi
, "atoi");
66 procedure clearerr
(stream
: FILEs
);
67 pragma Import
(C
, clearerr
, "clearerr");
69 function dup
(handle
: int
) return int
;
70 pragma Import
(C
, dup
, "dup");
72 function dup2
(from
, to
: int
) return int
;
73 pragma Import
(C
, dup2
, "dup2");
75 function fclose
(stream
: FILEs
) return int
;
76 pragma Import
(C
, fclose
, "fclose");
78 function fdopen
(handle
: int
; mode
: chars
) return FILEs
;
79 pragma Import
(C
, fdopen
, "fdopen");
81 function fflush
(stream
: FILEs
) return int
;
82 pragma Import
(C
, fflush
, "fflush");
84 function fgetc
(stream
: FILEs
) return int
;
85 pragma Import
(C
, fgetc
, "fgetc");
87 function fgets
(strng
: chars
; n
: int
; stream
: FILEs
) return chars
;
88 pragma Import
(C
, fgets
, "fgets");
93 encoding
: Filename_Encoding
:= Unspecified
) return FILEs
;
94 pragma Import
(C
, fopen
, "__gnat_fopen");
96 function fputc
(C
: int
; stream
: FILEs
) return int
;
97 pragma Import
(C
, fputc
, "fputc");
99 function fputs
(Strng
: chars
; Stream
: FILEs
) return int
;
100 pragma Import
(C
, fputs
, "fputs");
102 procedure free
(Ptr
: System
.Address
);
103 pragma Import
(C
, free
, "free");
109 encoding
: Filename_Encoding
:= Unspecified
) return FILEs
;
110 pragma Import
(C
, freopen
, "__gnat_freopen");
117 pragma Import
(C
, fseek
, "fseek");
119 function ftell
(stream
: FILEs
) return long
;
120 pragma Import
(C
, ftell
, "ftell");
122 function getenv
(S
: String) return System
.Address
;
123 pragma Import
(C
, getenv
, "getenv");
125 function isatty
(handle
: int
) return int
;
126 pragma Import
(C
, isatty
, "isatty");
128 function lseek
(fd
: int
; offset
: off_t
; direction
: int
) return off_t
;
129 pragma Import
(C
, lseek
, "lseek");
131 function malloc
(Size
: size_t
) return System
.Address
;
132 pragma Import
(C
, malloc
, "malloc");
134 function malloc32
(Size
: size_t
) return System
.Address
;
135 pragma Import
(C
, malloc32
, "malloc");
136 -- An uncalled alias for malloc except on 64bit systems needing to
137 -- allocate 32bit memory.
139 procedure memcpy
(S1
: System
.Address
; S2
: System
.Address
; N
: size_t
);
140 pragma Import
(C
, memcpy
, "memcpy");
142 procedure memmove
(S1
: System
.Address
; S2
: System
.Address
; N
: size_t
);
143 pragma Import
(C
, memmove
, "memmove");
145 procedure mktemp
(template
: chars
);
146 pragma Import
(C
, mktemp
, "mktemp");
148 function pclose
(stream
: System
.Address
) return int
;
149 pragma Import
(C
, pclose
, "pclose");
151 function popen
(command
, mode
: System
.Address
) return System
.Address
;
152 pragma Import
(C
, popen
, "popen");
155 (Ptr
: System
.Address
; Size
: size_t
) return System
.Address
;
156 pragma Import
(C
, realloc
, "realloc");
159 (Ptr
: System
.Address
; Size
: size_t
) return System
.Address
;
160 pragma Import
(C
, realloc32
, "realloc");
161 -- An uncalled alias for realloc except on 64bit systems needing to
162 -- allocate 32bit memory.
164 procedure rewind
(stream
: FILEs
);
165 pragma Import
(C
, rewind
, "rewind");
167 function rmdir
(dir_name
: String) return int
;
168 pragma Import
(C
, rmdir
, "__gnat_rmdir");
170 function chdir
(dir_name
: String) return int
;
171 pragma Import
(C
, chdir
, "__gnat_chdir");
179 pragma Import
(C
, setvbuf
, "setvbuf");
181 procedure tmpnam
(string : chars
);
182 pragma Import
(C
, tmpnam
, "tmpnam");
184 function tmpfile
return FILEs
;
185 pragma Import
(C
, tmpfile
, "tmpfile");
187 function ungetc
(c
: int
; stream
: FILEs
) return int
;
188 pragma Import
(C
, ungetc
, "ungetc");
190 function unlink
(filename
: chars
) return int
;
191 pragma Import
(C
, unlink
, "__gnat_unlink");
193 function open
(filename
: chars
; oflag
: int
) return int
;
194 pragma Import
(C
, open
, "open");
196 function close
(fd
: int
) return int
;
197 pragma Import
(C
, close
, "close");
199 function read
(fd
: int
; buffer
: chars
; nbytes
: int
) return int
;
200 pragma Import
(C
, read
, "read");
202 function write
(fd
: int
; buffer
: chars
; nbytes
: int
) return int
;
203 pragma Import
(C
, write
, "write");