2014-10-10 Robert Dewar <dewar@adacore.com>
[official-gcc.git] / gcc / ada / s-crtl.ads
blob835bbd9e3ae4f4b13a4b307903d290cec5aadefe
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . C R T L --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2003-2014, 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 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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 -- This package provides the low level interface to the C runtime library
34 pragma Compiler_Unit_Warning;
36 with System.Parameters;
38 package System.CRTL is
39 pragma Preelaborate;
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 int64 is range -(2 ** 63) .. (2 ** 63) - 1;
67 type Filename_Encoding is (UTF8, ASCII_8bits, Unspecified);
68 for Filename_Encoding use (UTF8 => 0, ASCII_8bits => 1, Unspecified => 2);
69 pragma Convention (C, Filename_Encoding);
70 -- Describes the filename's encoding
72 --------------------
73 -- GCC intrinsics --
74 --------------------
76 -- The following functions are imported with convention Intrinsic so that
77 -- we take advantage of back-end builtins if present (else we fall back
78 -- to C library functions by the same names).
80 function strlen (A : System.Address) return size_t;
81 pragma Import (Intrinsic, strlen, "strlen");
83 procedure strncpy (dest, src : System.Address; n : size_t);
84 pragma Import (Intrinsic, strncpy, "strncpy");
86 -------------------------------
87 -- Other C runtime functions --
88 -------------------------------
90 function atoi (A : System.Address) return Integer;
91 pragma Import (C, atoi, "atoi");
93 procedure clearerr (stream : FILEs);
94 pragma Import (C, clearerr, "clearerr");
96 function dup (handle : int) return int;
97 pragma Import (C, dup, "dup");
99 function dup2 (from, to : int) return int;
100 pragma Import (C, dup2, "dup2");
102 function fclose (stream : FILEs) return int;
103 pragma Import (C, fclose, "fclose");
105 function fdopen (handle : int; mode : chars) return FILEs;
106 pragma Import (C, fdopen, "fdopen");
108 function fflush (stream : FILEs) return int;
109 pragma Import (C, fflush, "fflush");
111 function fgetc (stream : FILEs) return int;
112 pragma Import (C, fgetc, "fgetc");
114 function fgets (strng : chars; n : int; stream : FILEs) return chars;
115 pragma Import (C, fgets, "fgets");
117 function fopen
118 (filename : chars;
119 mode : chars;
120 encoding : Filename_Encoding := Unspecified) return FILEs;
121 pragma Import (C, fopen, "__gnat_fopen");
123 function fputc (C : int; stream : FILEs) return int;
124 pragma Import (C, fputc, "fputc");
126 function fputwc (C : int; stream : FILEs) return int;
127 pragma Import (C, fputwc, "__gnat_fputwc");
129 function fputs (Strng : chars; Stream : FILEs) return int;
130 pragma Import (C, fputs, "fputs");
132 procedure free (Ptr : System.Address);
133 pragma Import (C, free, "free");
135 function freopen
136 (filename : chars;
137 mode : chars;
138 stream : FILEs;
139 encoding : Filename_Encoding := Unspecified) return FILEs;
140 pragma Import (C, freopen, "__gnat_freopen");
142 function fseek
143 (stream : FILEs;
144 offset : long;
145 origin : int) return int;
146 pragma Import (C, fseek, "fseek");
148 function fseek64
149 (stream : FILEs;
150 offset : int64;
151 origin : int) return int;
152 pragma Import (C, fseek64, "__gnat_fseek64");
154 function ftell (stream : FILEs) return long;
155 pragma Import (C, ftell, "ftell");
157 function ftell64 (stream : FILEs) return int64;
158 pragma Import (C, ftell64, "__gnat_ftell64");
160 function getenv (S : String) return System.Address;
161 pragma Import (C, getenv, "getenv");
163 function isatty (handle : int) return int;
164 pragma Import (C, isatty, "isatty");
166 function lseek (fd : int; offset : off_t; direction : int) return off_t;
167 pragma Import (C, lseek, "lseek");
169 function malloc (Size : size_t) return System.Address;
170 pragma Import (C, malloc, "malloc");
172 procedure memcpy (S1 : System.Address; S2 : System.Address; N : size_t);
173 pragma Import (C, memcpy, "memcpy");
175 procedure memmove (S1 : System.Address; S2 : System.Address; N : size_t);
176 pragma Import (C, memmove, "memmove");
178 procedure mktemp (template : chars);
179 pragma Import (C, mktemp, "mktemp");
181 function pclose (stream : System.Address) return int;
182 pragma Import (C, pclose, "pclose");
184 function popen (command, mode : System.Address) return System.Address;
185 pragma Import (C, popen, "popen");
187 function realloc
188 (Ptr : System.Address; Size : size_t) return System.Address;
189 pragma Import (C, realloc, "realloc");
191 procedure rewind (stream : FILEs);
192 pragma Import (C, rewind, "rewind");
194 function rmdir (dir_name : String) return int;
195 pragma Import (C, rmdir, "__gnat_rmdir");
197 function chdir (dir_name : String) return int;
198 pragma Import (C, chdir, "__gnat_chdir");
200 function mkdir
201 (dir_name : String;
202 encoding : Filename_Encoding := Unspecified) return int;
203 pragma Import (C, mkdir, "__gnat_mkdir");
205 function setvbuf
206 (stream : FILEs;
207 buffer : chars;
208 mode : int;
209 size : size_t) return int;
210 pragma Import (C, setvbuf, "setvbuf");
212 procedure tmpnam (str : chars);
213 pragma Import (C, tmpnam, "tmpnam");
215 function tmpfile return FILEs;
216 pragma Import (C, tmpfile, "tmpfile");
218 function ungetc (c : int; stream : FILEs) return int;
219 pragma Import (C, ungetc, "ungetc");
221 function unlink (filename : chars) return int;
222 pragma Import (C, unlink, "__gnat_unlink");
224 function open (filename : chars; oflag : int) return int;
225 pragma Import (C, open, "__gnat_open");
227 function close (fd : int) return int;
228 pragma Import (C, close, "close");
230 function read (fd : int; buffer : chars; count : size_t) return ssize_t;
231 pragma Import (C, read, "read");
233 function write (fd : int; buffer : chars; count : size_t) return ssize_t;
234 pragma Import (C, write, "write");
236 end System.CRTL;