| 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-2025, 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 |
------------------------------------------------------------------------------ |
| 31 |
|
| 32 |
-- This package provides the low level interface to the C runtime library |
| 33 |
|
| 34 |
with System.Parameters; |
| 35 |
|
| 36 |
package System.CRTL is |
| 37 |
pragma Preelaborate; |
| 38 |
|
| 39 |
subtype chars is System.Address; |
| 40 |
-- Pointer to null-terminated array of characters |
| 41 |
-- Should use Interfaces.C.Strings types instead, but this causes bootstrap |
| 42 |
-- issues as i-c contains Ada 2005 specific features, not compatible with |
| 43 |
-- older, Ada 95-only base compilers??? |
| 44 |
|
| 45 |
subtype DIRs is System.Address; |
| 46 |
-- Corresponds to the C type DIR* |
| 47 |
|
| 48 |
subtype FILEs is System.Address; |
| 49 |
-- Corresponds to the C type FILE* |
| 50 |
|
| 51 |
subtype int is Integer; |
| 52 |
|
| 53 |
type long is range -(2 ** (System.Parameters.long_bits - 1)) |
| 54 |
.. +(2 ** (System.Parameters.long_bits - 1)) - 1; |
| 55 |
|
| 56 |
subtype off_t is Long_Integer; |
| 57 |
|
| 58 |
type size_t is mod System.Memory_Size; |
| 59 |
|
| 60 |
type ssize_t is range -Memory_Size / 2 .. Memory_Size / 2 - 1; |
| 61 |
|
| 62 |
type int64 is new Long_Long_Integer; |
| 63 |
-- Note: we use Long_Long_Integer'First instead of -2 ** 63 to allow this |
| 64 |
-- unit to compile when using custom target configuration files where the |
| 65 |
-- maximum integer is 32 bits. This is useful for static analysis tools |
| 66 |
-- such as SPARK or CodePeer. In the normal case, Long_Long_Integer is |
| 67 |
-- always 64-bits so there is no difference. |
| 68 |
|
| 69 |
type Filename_Encoding is (UTF8, ASCII_8bits, Unspecified); |
| 70 |
for Filename_Encoding use (UTF8 => 0, ASCII_8bits => 1, Unspecified => 2); |
| 71 |
pragma Convention (C, Filename_Encoding); |
| 72 |
-- Describes the filename's encoding |
| 73 |
|
| 74 |
-------------------- |
| 75 |
-- GCC intrinsics -- |
| 76 |
-------------------- |
| 77 |
|
| 78 |
-- The following functions are imported with convention Intrinsic so that |
| 79 |
-- we take advantage of back-end builtins if present (else we fall back |
| 80 |
-- to C library functions by the same names). |
| 81 |
|
| 82 |
function strlen (A : System.Address) return size_t; |
| 83 |
pragma Import (Intrinsic, strlen, "strlen"); |
| 84 |
|
| 85 |
procedure strncpy (dest, src : System.Address; n : size_t); |
| 86 |
pragma Import (Intrinsic, strncpy, "strncpy"); |
| 87 |
|
| 88 |
------------------------------- |
| 89 |
-- Other C runtime functions -- |
| 90 |
------------------------------- |
| 91 |
|
| 92 |
function atoi (A : System.Address) return Integer; |
| 93 |
pragma Import (C, atoi, "atoi"); |
| 94 |
|
| 95 |
procedure clearerr (stream : FILEs); |
| 96 |
pragma Import (C, clearerr, "clearerr"); |
| 97 |
|
| 98 |
function dup (handle : int) return int; |
| 99 |
pragma Import (C, dup, "dup"); |
| 100 |
|
| 101 |
function dup2 (from, to : int) return int; |
| 102 |
pragma Import (C, dup2, "dup2"); |
| 103 |
|
| 104 |
function fclose (stream : FILEs) return int; |
| 105 |
pragma Import (C, fclose, "fclose"); |
| 106 |
|
| 107 |
function fdopen (handle : int; mode : chars) return FILEs; |
| 108 |
pragma Import (C, fdopen, "fdopen"); |
| 109 |
|
| 110 |
function fflush (stream : FILEs) return int; |
| 111 |
pragma Import (C, fflush, "fflush"); |
| 112 |
|
| 113 |
function fgetc (stream : FILEs) return int; |
| 114 |
pragma Import (C, fgetc, "fgetc"); |
| 115 |
|
| 116 |
function fgets (strng : chars; n : int; stream : FILEs) return chars; |
| 117 |
pragma Import (C, fgets, "fgets"); |
| 118 |
|
| 119 |
function fopen |
| 120 |
(filename : chars; |
| 121 |
mode : chars; |
| 122 |
encoding : Filename_Encoding := Unspecified) return FILEs; |
| 123 |
pragma Import (C, fopen, "__gnat_fopen"); |
| 124 |
|
| 125 |
function fputc (C : int; stream : FILEs) return int; |
| 126 |
pragma Import (C, fputc, "fputc"); |
| 127 |
|
| 128 |
function fputwc (C : int; stream : FILEs) return int; |
| 129 |
pragma Import (C, fputwc, "__gnat_fputwc"); |
| 130 |
|
| 131 |
function fputs (Strng : chars; Stream : FILEs) return int; |
| 132 |
pragma Import (C, fputs, "fputs"); |
| 133 |
|
| 134 |
procedure free (Ptr : System.Address); |
| 135 |
pragma Import (C, free, "free"); |
| 136 |
|
| 137 |
function freopen |
| 138 |
(filename : chars; |
| 139 |
mode : chars; |
| 140 |
stream : FILEs; |
| 141 |
encoding : Filename_Encoding := Unspecified) return FILEs; |
| 142 |
pragma Import (C, freopen, "__gnat_freopen"); |
| 143 |
|
| 144 |
function fseek |
| 145 |
(stream : FILEs; |
| 146 |
offset : long; |
| 147 |
origin : int) return int; |
| 148 |
pragma Import (C, fseek, "fseek"); |
| 149 |
|
| 150 |
function fseek64 |
| 151 |
(stream : FILEs; |
| 152 |
offset : int64; |
| 153 |
origin : int) return int; |
| 154 |
pragma Import (C, fseek64, "__gnat_fseek64"); |
| 155 |
|
| 156 |
function ftell (stream : FILEs) return long; |
| 157 |
pragma Import (C, ftell, "ftell"); |
| 158 |
|
| 159 |
function ftell64 (stream : FILEs) return int64; |
| 160 |
pragma Import (C, ftell64, "__gnat_ftell64"); |
| 161 |
|
| 162 |
function getenv (S : String) return System.Address; |
| 163 |
pragma Import (C, getenv, "getenv"); |
| 164 |
|
| 165 |
function isatty (handle : int) return int; |
| 166 |
pragma Import (C, isatty, "isatty"); |
| 167 |
|
| 168 |
function lseek (fd : int; offset : off_t; direction : int) return off_t; |
| 169 |
pragma Import (C, lseek, "lseek"); |
| 170 |
|
| 171 |
function malloc (Size : size_t) return System.Address; |
| 172 |
pragma Import (C, malloc, "malloc"); |
| 173 |
|
| 174 |
procedure memcpy (S1 : System.Address; S2 : System.Address; N : size_t); |
| 175 |
pragma Import (C, memcpy, "memcpy"); |
| 176 |
|
| 177 |
procedure memmove (S1 : System.Address; S2 : System.Address; N : size_t); |
| 178 |
pragma Import (C, memmove, "memmove"); |
| 179 |
|
| 180 |
procedure mktemp (template : chars); |
| 181 |
pragma Import (C, mktemp, "mktemp"); |
| 182 |
|
| 183 |
function pclose (stream : System.Address) return int; |
| 184 |
pragma Import (C, pclose, "pclose"); |
| 185 |
|
| 186 |
function popen (command, mode : System.Address) return System.Address; |
| 187 |
pragma Import (C, popen, "popen"); |
| 188 |
|
| 189 |
function realloc |
| 190 |
(Ptr : System.Address; Size : size_t) return System.Address; |
| 191 |
pragma Import (C, realloc, "realloc"); |
| 192 |
|
| 193 |
procedure rewind (stream : FILEs); |
| 194 |
pragma Import (C, rewind, "rewind"); |
| 195 |
|
| 196 |
function rmdir (dir_name : String) return int; |
| 197 |
pragma Import (C, rmdir, "__gnat_rmdir"); |
| 198 |
|
| 199 |
function chdir (dir_name : String) return int; |
| 200 |
pragma Import (C, chdir, "__gnat_chdir"); |
| 201 |
|
| 202 |
function mkdir |
| 203 |
(dir_name : String; |
| 204 |
encoding : Filename_Encoding := Unspecified) return int; |
| 205 |
pragma Import (C, mkdir, "__gnat_mkdir"); |
| 206 |
|
| 207 |
function setvbuf |
| 208 |
(stream : FILEs; |
| 209 |
buffer : chars; |
| 210 |
mode : int; |
| 211 |
size : size_t) return int; |
| 212 |
pragma Import (C, setvbuf, "setvbuf"); |
| 213 |
|
| 214 |
procedure tmpnam (str : chars); |
| 215 |
pragma Import (C, tmpnam, "tmpnam"); |
| 216 |
|
| 217 |
function tmpfile return FILEs; |
| 218 |
pragma Import (C, tmpfile, "tmpfile"); |
| 219 |
|
| 220 |
function ungetc (c : int; stream : FILEs) return int; |
| 221 |
pragma Import (C, ungetc, "ungetc"); |
| 222 |
|
| 223 |
function unlink (filename : chars; |
| 224 |
encoding : Filename_Encoding := Unspecified) return int; |
| 225 |
pragma Import (C, unlink, "__gnat_unlink"); |
| 226 |
|
| 227 |
function open (filename : chars; oflag : int) return int; |
| 228 |
pragma Import (C, open, "__gnat_open"); |
| 229 |
|
| 230 |
function close (fd : int) return int; |
| 231 |
pragma Import (C, close, "close"); |
| 232 |
|
| 233 |
function read (fd : int; buffer : chars; count : size_t) return ssize_t; |
| 234 |
pragma Import (C, read, "read"); |
| 235 |
|
| 236 |
function write (fd : int; buffer : chars; count : size_t) return ssize_t; |
| 237 |
pragma Import (C, write, "write"); |
| 238 |
|
| 239 |
end System.CRTL; |