gcc:
[official-gcc.git] / gcc / ada / i-cstrea.ads
bloba7a30b2d3c40698de169cc0ba81d181c62d7e485
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- I N T E R F A C E S . C _ S T R E A M S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1995-2005, 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 -- This package is a thin binding to selected functions in the C
35 -- library that provide a complete interface for handling C streams.
37 with System.CRTL;
39 package Interfaces.C_Streams is
40 pragma Preelaborate;
42 subtype chars is System.CRTL.chars;
43 subtype FILEs is System.CRTL.FILEs;
44 subtype int is System.CRTL.int;
45 subtype long is System.CRTL.long;
46 subtype size_t is System.CRTL.size_t;
47 subtype voids is System.Address;
49 NULL_Stream : constant FILEs;
50 -- Value returned (NULL in C) to indicate an fdopen/fopen/tmpfile error
52 ----------------------------------
53 -- Constants Defined in stdio.h --
54 ----------------------------------
56 EOF : constant int;
57 -- Used by a number of routines to indicate error or end of file
59 IOFBF : constant int;
60 IOLBF : constant int;
61 IONBF : constant int;
62 -- Used to indicate buffering mode for setvbuf call
64 L_tmpnam : constant int;
65 -- Maximum length of file name that can be returned by tmpnam
67 SEEK_CUR : constant int;
68 SEEK_END : constant int;
69 SEEK_SET : constant int;
70 -- Used to indicate origin for fseek call
72 function stdin return FILEs;
73 function stdout return FILEs;
74 function stderr return FILEs;
75 -- Streams associated with standard files
77 --------------------------
78 -- Standard C functions --
79 --------------------------
81 -- The functions selected below are ones that are available in DOS,
82 -- OS/2, UNIX and Xenix (but not necessarily in ANSI C). These are
83 -- very thin interfaces which copy exactly the C headers. For more
84 -- documentation on these functions, see the Microsoft C "Run-Time
85 -- Library Reference" (Microsoft Press, 1990, ISBN 1-55615-225-6),
86 -- which includes useful information on system compatibility.
88 procedure clearerr (stream : FILEs) renames System.CRTL.clearerr;
90 function fclose (stream : FILEs) return int renames System.CRTL.fclose;
92 function fdopen (handle : int; mode : chars) return FILEs
93 renames System.CRTL.fdopen;
95 function feof (stream : FILEs) return int;
97 function ferror (stream : FILEs) return int;
99 function fflush (stream : FILEs) return int renames System.CRTL.fflush;
101 function fgetc (stream : FILEs) return int renames System.CRTL.fgetc;
103 function fgets (strng : chars; n : int; stream : FILEs) return chars
104 renames System.CRTL.fgets;
106 function fileno (stream : FILEs) return int;
108 function fopen (filename : chars; Mode : chars) return FILEs
109 renames System.CRTL.fopen;
110 -- Note: to maintain target independence, use text_translation_required,
111 -- a boolean variable defined in a-sysdep.c to deal with the target
112 -- dependent text translation requirement. If this variable is set,
113 -- then b/t should be appended to the standard mode argument to set
114 -- the text translation mode off or on as required.
116 function fputc (C : int; stream : FILEs) return int
117 renames System.CRTL.fputc;
119 function fputs (Strng : chars; Stream : FILEs) return int
120 renames System.CRTL.fputs;
122 function fread
123 (buffer : voids;
124 size : size_t;
125 count : size_t;
126 stream : FILEs) return size_t;
128 function fread
129 (buffer : voids;
130 index : size_t;
131 size : size_t;
132 count : size_t;
133 stream : FILEs) return size_t;
134 -- Same as normal fread, but has a parameter 'index' that indicates
135 -- the starting index for the read within 'buffer' (which must be the
136 -- address of the beginning of a whole array object with an assumed
137 -- zero base). This is needed for systems that do not support taking
138 -- the address of an element within an array.
140 function freopen
141 (filename : chars;
142 mode : chars;
143 stream : FILEs)
144 return FILEs renames System.CRTL.freopen;
146 function fseek
147 (stream : FILEs;
148 offset : long;
149 origin : int)
150 return int renames System.CRTL.fseek;
152 function ftell (stream : FILEs) return long
153 renames System.CRTL.ftell;
155 function fwrite
156 (buffer : voids;
157 size : size_t;
158 count : size_t;
159 stream : FILEs)
160 return size_t;
162 function isatty (handle : int) return int renames System.CRTL.isatty;
164 procedure mktemp (template : chars) renames System.CRTL.mktemp;
165 -- The return value (which is just a pointer to template) is discarded
167 procedure rewind (stream : FILEs) renames System.CRTL.rewind;
169 function setvbuf
170 (stream : FILEs;
171 buffer : chars;
172 mode : int;
173 size : size_t)
174 return int;
176 procedure tmpnam (string : chars) renames System.CRTL.tmpnam;
177 -- The parameter must be a pointer to a string buffer of at least L_tmpnam
178 -- bytes (the call with a null parameter is not supported). The returned
179 -- value, which is just a copy of the input argument, is discarded.
181 function tmpfile return FILEs renames System.CRTL.tmpfile;
183 function ungetc (c : int; stream : FILEs) return int
184 renames System.CRTL.ungetc;
186 function unlink (filename : chars) return int
187 renames System.CRTL.unlink;
189 ---------------------
190 -- Extra functions --
191 ---------------------
193 -- These functions supply slightly thicker bindings than those above.
194 -- They are derived from functions in the C Run-Time Library, but may
195 -- do a bit more work than just directly calling one of the Library
196 -- functions.
198 function file_exists (name : chars) return int;
199 -- Tests if given name corresponds to an existing file
201 function is_regular_file (handle : int) return int;
202 -- Tests if given handle is for a regular file (result 1) or for a
203 -- non-regular file (pipe or device, result 0).
205 ---------------------------------
206 -- Control of Text/Binary Mode --
207 ---------------------------------
209 -- If text_translation_required is true, then the following functions may
210 -- be used to dynamically switch a file from binary to text mode or vice
211 -- versa. These functions have no effect if text_translation_required is
212 -- false (i.e. in normal unix mode). Use fileno to get a stream handle.
214 procedure set_binary_mode (handle : int);
215 procedure set_text_mode (handle : int);
217 ----------------------------
218 -- Full Path Name support --
219 ----------------------------
221 procedure full_name (nam : chars; buffer : chars);
222 -- Given a NUL terminated string representing a file name, returns in
223 -- buffer a NUL terminated string representing the full path name for
224 -- the file name. On systems where it is relevant the drive is also part
225 -- of the full path name. It is the responsibility of the caller to
226 -- pass an actual parameter for buffer that is big enough for any full
227 -- path name. Use max_path_len given below as the size of buffer.
229 max_path_len : Integer;
230 -- Maximum length of an allowable full path name on the system,
231 -- including a terminating NUL character.
233 private
234 -- The following functions are specialized in the body depending on the
235 -- operating system.
237 pragma Inline (fread);
238 pragma Inline (fwrite);
239 pragma Inline (setvbuf);
241 pragma Import (C, file_exists, "__gnat_file_exists");
242 pragma Import (C, is_regular_file, "__gnat_is_regular_file_fd");
244 pragma Import (C, set_binary_mode, "__gnat_set_binary_mode");
245 pragma Import (C, set_text_mode, "__gnat_set_text_mode");
247 pragma Import (C, max_path_len, "__gnat_max_path_len");
248 pragma Import (C, full_name, "__gnat_full_name");
250 -- The following may be implemented as macros, and so are supported
251 -- via an interface function in the a-cstrea.c file.
253 pragma Import (C, feof, "__gnat_feof");
254 pragma Import (C, ferror, "__gnat_ferror");
255 pragma Import (C, fileno, "__gnat_fileno");
257 pragma Import (C, EOF, "__gnat_constant_eof");
258 pragma Import (C, IOFBF, "__gnat_constant_iofbf");
259 pragma Import (C, IOLBF, "__gnat_constant_iolbf");
260 pragma Import (C, IONBF, "__gnat_constant_ionbf");
261 pragma Import (C, SEEK_CUR, "__gnat_constant_seek_cur");
262 pragma Import (C, SEEK_END, "__gnat_constant_seek_end");
263 pragma Import (C, SEEK_SET, "__gnat_constant_seek_set");
264 pragma Import (C, L_tmpnam, "__gnat_constant_l_tmpnam");
266 pragma Import (C, stderr, "__gnat_constant_stderr");
267 pragma Import (C, stdin, "__gnat_constant_stdin");
268 pragma Import (C, stdout, "__gnat_constant_stdout");
270 NULL_Stream : constant FILEs := System.Null_Address;
272 end Interfaces.C_Streams;