1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . C R T L --
9 -- Copyright (C) 2003-2012, 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 runtime library
36 with System
.Parameters
;
38 package System
.CRTL
is
41 subtype chars
is System
.Address
;
42 -- Pointer to null-terminated array of characters
43 -- Should use Interfaces.C.Strings types instead, but this causes bootstrap
44 -- issues as i-c contains Ada 2005 specific features, not compatible with
45 -- older, Ada 95-only base compilers???
47 subtype DIRs
is System
.Address
;
48 -- Corresponds to the C type DIR*
50 subtype FILEs
is System
.Address
;
51 -- Corresponds to the C type FILE*
53 subtype int
is Integer;
55 type long
is range -(2 ** (System
.Parameters
.long_bits
- 1))
56 .. +(2 ** (System
.Parameters
.long_bits
- 1)) - 1;
58 subtype off_t
is Long_Integer;
60 type size_t
is mod 2 ** Standard
'Address_Size;
62 type ssize_t
is range -(2 ** (Standard
'Address_Size - 1))
63 .. +(2 ** (Standard
'Address_Size - 1)) - 1;
65 type Filename_Encoding
is (UTF8
, ASCII_8bits
, Unspecified
);
66 for Filename_Encoding
use (UTF8
=> 0, ASCII_8bits
=> 1, Unspecified
=> 2);
67 pragma Convention
(C
, Filename_Encoding
);
68 -- Describes the filename's encoding
70 function atoi
(A
: System
.Address
) return Integer;
71 pragma Import
(C
, atoi
, "atoi");
73 procedure clearerr
(stream
: FILEs
);
74 pragma Import
(C
, clearerr
, "clearerr");
76 function dup
(handle
: int
) return int
;
77 pragma Import
(C
, dup
, "dup");
79 function dup2
(from
, to
: int
) return int
;
80 pragma Import
(C
, dup2
, "dup2");
82 function fclose
(stream
: FILEs
) return int
;
83 pragma Import
(C
, fclose
, "fclose");
85 function fdopen
(handle
: int
; mode
: chars
) return FILEs
;
86 pragma Import
(C
, fdopen
, "fdopen");
88 function fflush
(stream
: FILEs
) return int
;
89 pragma Import
(C
, fflush
, "fflush");
91 function fgetc
(stream
: FILEs
) return int
;
92 pragma Import
(C
, fgetc
, "fgetc");
94 function fgets
(strng
: chars
; n
: int
; stream
: FILEs
) return chars
;
95 pragma Import
(C
, fgets
, "fgets");
100 encoding
: Filename_Encoding
:= Unspecified
) return FILEs
;
101 pragma Import
(C
, fopen
, "__gnat_fopen");
103 function fputc
(C
: int
; stream
: FILEs
) return int
;
104 pragma Import
(C
, fputc
, "fputc");
106 function fputs
(Strng
: chars
; Stream
: FILEs
) return int
;
107 pragma Import
(C
, fputs
, "fputs");
109 procedure free
(Ptr
: System
.Address
);
110 pragma Import
(C
, free
, "free");
116 encoding
: Filename_Encoding
:= Unspecified
) return FILEs
;
117 pragma Import
(C
, freopen
, "__gnat_freopen");
122 origin
: int
) return int
;
123 pragma Import
(C
, fseek
, "fseek");
128 origin
: int
) return int
;
129 pragma Import
(C
, fseek64
, "__gnat_fseek64");
131 function ftell
(stream
: FILEs
) return long
;
132 pragma Import
(C
, ftell
, "ftell");
134 function ftell64
(stream
: FILEs
) return ssize_t
;
135 pragma Import
(C
, ftell64
, "__gnat_ftell64");
137 function getenv
(S
: String) return System
.Address
;
138 pragma Import
(C
, getenv
, "getenv");
140 function isatty
(handle
: int
) return int
;
141 pragma Import
(C
, isatty
, "isatty");
143 function lseek
(fd
: int
; offset
: off_t
; direction
: int
) return off_t
;
144 pragma Import
(C
, lseek
, "lseek");
146 function malloc
(Size
: size_t
) return System
.Address
;
147 pragma Import
(C
, malloc
, "malloc");
149 procedure memcpy
(S1
: System
.Address
; S2
: System
.Address
; N
: size_t
);
150 pragma Import
(C
, memcpy
, "memcpy");
152 procedure memmove
(S1
: System
.Address
; S2
: System
.Address
; N
: size_t
);
153 pragma Import
(C
, memmove
, "memmove");
155 procedure mktemp
(template
: chars
);
156 pragma Import
(C
, mktemp
, "mktemp");
158 function pclose
(stream
: System
.Address
) return int
;
159 pragma Import
(C
, pclose
, "pclose");
161 function popen
(command
, mode
: System
.Address
) return System
.Address
;
162 pragma Import
(C
, popen
, "popen");
165 (Ptr
: System
.Address
; Size
: size_t
) return System
.Address
;
166 pragma Import
(C
, realloc
, "realloc");
168 procedure rewind
(stream
: FILEs
);
169 pragma Import
(C
, rewind
, "rewind");
171 function rmdir
(dir_name
: String) return int
;
172 pragma Import
(C
, rmdir
, "__gnat_rmdir");
174 function chdir
(dir_name
: String) return int
;
175 pragma Import
(C
, chdir
, "__gnat_chdir");
179 encoding
: Filename_Encoding
:= Unspecified
) return int
;
180 pragma Import
(C
, mkdir
, "__gnat_mkdir");
186 size
: size_t
) return int
;
187 pragma Import
(C
, setvbuf
, "setvbuf");
189 procedure tmpnam
(str
: chars
);
190 pragma Import
(C
, tmpnam
, "tmpnam");
192 function tmpfile
return FILEs
;
193 pragma Import
(C
, tmpfile
, "tmpfile");
195 function ungetc
(c
: int
; stream
: FILEs
) return int
;
196 pragma Import
(C
, ungetc
, "ungetc");
198 function unlink
(filename
: chars
) return int
;
199 pragma Import
(C
, unlink
, "__gnat_unlink");
201 function open
(filename
: chars
; oflag
: int
) return int
;
202 pragma Import
(C
, open
, "open");
204 function close
(fd
: int
) return int
;
205 pragma Import
(C
, close
, "close");
207 function read
(fd
: int
; buffer
: chars
; count
: size_t
) return ssize_t
;
208 pragma Import
(C
, read
, "read");
210 function write
(fd
: int
; buffer
: chars
; count
: size_t
) return ssize_t
;
211 pragma Import
(C
, write
, "write");