* include/javaprims.h: Removed security namespace.
[official-gcc.git] / libio / libioP.h
blob36fa1e007ded23d4dfab05f94c34050cc8ed18c5
1 /* Copyright (C) 1993, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU IO Library.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2, or (at
7 your option) any later version.
9 This library is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this library; see the file COPYING. If not, write to
16 the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
17 MA 02111-1307, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does
21 not cause the resulting executable to be covered by the GNU General
22 Public License. This exception does not however invalidate any
23 other reasons why the executable file might be covered by the GNU
24 General Public License. */
26 #ifndef _POSIX_SOURCE
27 # define _POSIX_SOURCE
28 #endif
30 #include <errno.h>
31 #ifndef __set_errno
32 # define __set_errno(Val) errno = (Val)
33 #endif
34 #if defined __GLIBC__ && __GLIBC__ >= 2
35 # if __GLIBC_MINOR__ > 0
36 # include <bits/libc-lock.h>
37 # else
38 # include <libc-lock.h>
39 # endif
40 #else
41 /*# include <comthread.h>*/
42 #endif
44 #include "iolibio.h"
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
50 #define _IO_seek_set 0
51 #define _IO_seek_cur 1
52 #define _IO_seek_end 2
54 /* THE JUMPTABLE FUNCTIONS.
56 * The _IO_FILE type is used to implement the FILE type in GNU libc,
57 * as well as the streambuf class in GNU iostreams for C++.
58 * These are all the same, just used differently.
59 * An _IO_FILE (or FILE) object is allows followed by a pointer to
60 * a jump table (of pointers to functions). The pointer is accessed
61 * with the _IO_JUMPS macro. The jump table has a eccentric format,
62 * so as to be compatible with the layout of a C++ virtual function table.
63 * (as implemented by g++). When a pointer to a streambuf object is
64 * coerced to an (_IO_FILE*), then _IO_JUMPS on the result just
65 * happens to point to the virtual function table of the streambuf.
66 * Thus the _IO_JUMPS function table used for C stdio/libio does
67 * double duty as the virtual function table for C++ streambuf.
69 * The entries in the _IO_JUMPS function table (and hence also the
70 * virtual functions of a streambuf) are described below.
71 * The first parameter of each function entry is the _IO_FILE/streambuf
72 * object being acted on (i.e. the 'this' parameter).
75 #define _IO_JUMPS(THIS) ((struct _IO_FILE_plus *) (THIS))->vtable
76 #ifdef _G_USING_THUNKS
77 # define JUMP_FIELD(TYPE, NAME) TYPE NAME
78 # define JUMP0(FUNC, THIS) _IO_JUMPS(THIS)->FUNC (THIS)
79 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS(THIS)->FUNC (THIS, X1)
80 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS(THIS)->FUNC (THIS, X1, X2)
81 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS(THIS)->FUNC (THIS, X1,X2, X3)
82 # define JUMP_INIT(NAME, VALUE) VALUE
83 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
84 #else
85 /* These macros will change when we re-implement vtables to use "thunks"! */
86 # define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME
87 # define JUMP0(FUNC, THIS) _IO_JUMPS(THIS)->FUNC.pfn (THIS)
88 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS(THIS)->FUNC.pfn (THIS, X1)
89 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS(THIS)->FUNC.pfn (THIS, X1, X2)
90 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS(THIS)->FUNC.pfn (THIS, X1,X2,X3)
91 # define JUMP_INIT(NAME, VALUE) {0, 0, VALUE}
92 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0)
93 #endif
95 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
96 It does not delete (free) it, but does everything else to finalize it/
97 It matches the streambuf::~streambuf virtual destructor. */
98 typedef void (*_IO_finish_t) __PMT ((_IO_FILE *, int)); /* finalize */
99 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
101 /* The 'overflow' hook flushes the buffer.
102 The second argument is a character, or EOF.
103 It matches the streambuf::overflow virtual function. */
104 typedef int (*_IO_overflow_t) __PMT ((_IO_FILE *, int));
105 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
107 /* The 'underflow' hook tries to fills the get buffer.
108 It returns the next character (as an unsigned char) or EOF. The next
109 character remains in the get buffer, and the get position is not changed.
110 It matches the streambuf::underflow virtual function. */
111 typedef int (*_IO_underflow_t) __PMT ((_IO_FILE *));
112 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
114 /* The 'uflow' hook returns the next character in the input stream
115 (cast to unsigned char), and increments the read position;
116 EOF is returned on failure.
117 It matches the streambuf::uflow virtual function, which is not in the
118 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
119 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
121 /* The 'pbackfail' hook handles backing up.
122 It matches the streambuf::pbackfail virtual function. */
123 typedef int (*_IO_pbackfail_t) __PMT ((_IO_FILE *, int));
124 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
126 /* The 'xsputn' hook writes upto N characters from buffer DATA.
127 Returns the number of character actually written.
128 It matches the streambuf::xsputn virtual function. */
129 typedef _IO_size_t (*_IO_xsputn_t) __PMT ((_IO_FILE *FP, const void *DATA,
130 _IO_size_t N));
131 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
133 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
134 Returns the number of character actually read.
135 It matches the streambuf::xsgetn virtual function. */
136 typedef _IO_size_t (*_IO_xsgetn_t) __PMT ((_IO_FILE *FP, void *DATA,
137 _IO_size_t N));
138 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
140 /* The 'seekoff' hook moves the stream position to a new position
141 relative to the start of the file (if DIR==0), the current position
142 (MODE==1), or the end of the file (MODE==2).
143 It matches the streambuf::seekoff virtual function.
144 It is also used for the ANSI fseek function. */
145 #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
146 typedef _IO_fpos64_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP, _IO_off64_t OFF,
147 int DIR, int MODE));
148 #else
149 typedef _IO_fpos_t (*_IO_seekoff_t) __PMT ((_IO_FILE *FP, _IO_off_t OFF,
150 int DIR, int MODE));
151 #endif
152 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
154 /* The 'seekpos' hook also moves the stream position,
155 but to an absolute position given by a fpos_t (seekpos).
156 It matches the streambuf::seekpos virtual function.
157 It is also used for the ANSI fgetpos and fsetpos functions. */
158 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
159 #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
160 typedef _IO_fpos64_t (*_IO_seekpos_t) __PMT ((_IO_FILE *, _IO_fpos64_t, int));
161 #else
162 typedef _IO_fpos_t (*_IO_seekpos_t) __PMT ((_IO_FILE *, _IO_fpos_t, int));
163 #endif
164 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
166 /* The 'setbuf' hook gives a buffer to the file.
167 It matches the streambuf::setbuf virtual function. */
168 typedef _IO_FILE* (*_IO_setbuf_t) __PMT ((_IO_FILE *, char *, _IO_ssize_t));
169 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
171 /* The 'sync' hook attempts to synchronize the internal data structures
172 of the file with the external state.
173 It matches the streambuf::sync virtual function. */
174 typedef int (*_IO_sync_t) __PMT ((_IO_FILE *));
175 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
177 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
178 It matches the streambuf::doallocate virtual function, which is not
179 in the ANSI/ISO C++ standard, but is part traditional implementations. */
180 typedef int (*_IO_doallocate_t) __PMT ((_IO_FILE *));
181 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
183 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
184 sysstat) are low-level hooks specific to this implementation.
185 There is no correspondence in the ANSI/ISO C++ standard library.
186 The hooks basically correspond to the Unix system functions
187 (read, write, close, lseek, and stat) except that a _IO_FILE*
188 parameter is used instead of a integer file descriptor; the default
189 implementation used for normal files just calls those functions.
190 The advantage of overriding these functions instead of the higher-level
191 ones (underflow, overflow etc) is that you can leave all the buffering
192 higher-level functions. */
194 /* The 'sysread' hook is used to read data from the external file into
195 an existing buffer. It generalizes the Unix read(2) function.
196 It matches the streambuf::sys_read virtual function, which is
197 specific to this implementation. */
198 typedef _IO_ssize_t (*_IO_read_t) __PMT ((_IO_FILE *, void *, _IO_ssize_t));
199 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
201 /* The 'syswrite' hook is used to write data from an existing buffer
202 to an external file. It generalizes the Unix write(2) function.
203 It matches the streambuf::sys_write virtual function, which is
204 specific to this implementation. */
205 typedef _IO_ssize_t (*_IO_write_t) __PMT ((_IO_FILE *,const void *,_IO_ssize_t));
206 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
208 /* The 'sysseek' hook is used to re-position an external file.
209 It generalizes the Unix lseek(2) function.
210 It matches the streambuf::sys_seek virtual function, which is
211 specific to this implementation. */
212 #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
213 typedef _IO_fpos64_t (*_IO_seek_t) __PMT ((_IO_FILE *, _IO_off64_t, int));
214 #else
215 typedef _IO_fpos_t (*_IO_seek_t) __PMT ((_IO_FILE *, _IO_off_t, int));
216 #endif
217 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
219 /* The 'sysclose' hook is used to finalize (close, finish up) an
220 external file. It generalizes the Unix close(2) function.
221 It matches the streambuf::sys_close virtual function, which is
222 specific to this implementation. */
223 typedef int (*_IO_close_t) __PMT ((_IO_FILE *)); /* finalize */
224 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
226 /* The 'sysstat' hook is used to get information about an external file
227 into a struct stat buffer. It generalizes the Unix fstat(2) call.
228 It matches the streambuf::sys_stat virtual function, which is
229 specific to this implementation. */
230 typedef int (*_IO_stat_t) __PMT ((_IO_FILE *, void *));
231 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
233 #if _G_IO_IO_FILE_VERSION == 0x20001
234 /* The 'showmany' hook can be used to get an image how much input is
235 available. In many cases the answer will be 0 which means unknown
236 but some cases one can provide real information. */
237 typedef int (*_IO_showmanyc_t) __PMT ((_IO_FILE *));
238 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
240 /* The 'imbue' hook is used to get information about the currently
241 installed locales. */
242 typedef void (*_IO_imbue_t) __PMT ((_IO_FILE *, void *));
243 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
244 #endif
247 #define _IO_CHAR_TYPE char /* unsigned char ? */
248 #define _IO_INT_TYPE int
250 struct _IO_jump_t
252 JUMP_FIELD(_G_size_t, __dummy);
253 #ifdef _G_USING_THUNKS
254 JUMP_FIELD(_G_size_t, __dummy2);
255 #endif
256 JUMP_FIELD(_IO_finish_t, __finish);
257 JUMP_FIELD(_IO_overflow_t, __overflow);
258 JUMP_FIELD(_IO_underflow_t, __underflow);
259 JUMP_FIELD(_IO_underflow_t, __uflow);
260 JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
261 /* showmany */
262 JUMP_FIELD(_IO_xsputn_t, __xsputn);
263 JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
264 JUMP_FIELD(_IO_seekoff_t, __seekoff);
265 JUMP_FIELD(_IO_seekpos_t, __seekpos);
266 JUMP_FIELD(_IO_setbuf_t, __setbuf);
267 JUMP_FIELD(_IO_sync_t, __sync);
268 JUMP_FIELD(_IO_doallocate_t, __doallocate);
269 JUMP_FIELD(_IO_read_t, __read);
270 JUMP_FIELD(_IO_write_t, __write);
271 JUMP_FIELD(_IO_seek_t, __seek);
272 JUMP_FIELD(_IO_close_t, __close);
273 JUMP_FIELD(_IO_stat_t, __stat);
274 #if _G_IO_IO_FILE_VERSION == 0x20001
275 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
276 JUMP_FIELD(_IO_imbue_t, __imbue);
277 #endif
278 #if 0
279 get_column;
280 set_column;
281 #endif
284 /* We always allocate an extra word following an _IO_FILE.
285 This contains a pointer to the function jump table used.
286 This is for compatibility with C++ streambuf; the word can
287 be used to smash to a pointer to a virtual function table. */
289 struct _IO_FILE_plus
291 _IO_FILE file;
292 const struct _IO_jump_t *vtable;
295 /* Generic functions */
297 #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
298 extern _IO_fpos64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
299 extern _IO_fpos64_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos64_t, int));
300 #else
301 extern _IO_fpos_t _IO_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
302 extern _IO_fpos_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos_t, int));
303 #endif
305 extern void _IO_switch_to_main_get_area __P ((_IO_FILE *));
306 extern void _IO_switch_to_backup_area __P ((_IO_FILE *));
307 extern int _IO_switch_to_get_mode __P ((_IO_FILE *));
308 extern void _IO_init __P ((_IO_FILE *, int));
309 extern int _IO_sputbackc __P ((_IO_FILE *, int));
310 extern int _IO_sungetc __P ((_IO_FILE *));
311 extern void _IO_un_link __P ((_IO_FILE *));
312 extern void _IO_link_in __P ((_IO_FILE *));
313 extern void _IO_doallocbuf __P ((_IO_FILE *));
314 extern void _IO_unsave_markers __P ((_IO_FILE *));
315 extern void _IO_setb __P ((_IO_FILE *, char *, char *, int));
316 extern unsigned _IO_adjust_column __P ((unsigned, const char *, int));
317 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
319 /* Marker-related function. */
321 extern void _IO_init_marker __P ((struct _IO_marker *, _IO_FILE *));
322 extern void _IO_remove_marker __P ((struct _IO_marker *));
323 extern int _IO_marker_difference __P ((struct _IO_marker *,
324 struct _IO_marker *));
325 extern int _IO_marker_delta __P ((struct _IO_marker *));
326 extern int _IO_seekmark __P ((_IO_FILE *, struct _IO_marker *, int));
328 /* Default jumptable functions. */
330 extern int _IO_default_underflow __P ((_IO_FILE *));
331 extern int _IO_default_uflow __P ((_IO_FILE *));
332 extern int _IO_default_doallocate __P ((_IO_FILE *));
333 extern void _IO_default_finish __P ((_IO_FILE *, int));
334 extern int _IO_default_pbackfail __P ((_IO_FILE *, int));
335 extern _IO_FILE* _IO_default_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
336 extern _IO_size_t _IO_default_xsputn __P ((_IO_FILE *, const void *,
337 _IO_size_t));
338 extern _IO_size_t _IO_default_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
339 #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
340 extern _IO_fpos64_t _IO_default_seekoff __P ((_IO_FILE *,
341 _IO_off64_t, int, int));
342 extern _IO_fpos64_t _IO_default_seekpos __P ((_IO_FILE *,
343 _IO_fpos64_t, int));
344 #else
345 extern _IO_fpos_t _IO_default_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
346 extern _IO_fpos_t _IO_default_seekpos __P ((_IO_FILE *, _IO_fpos_t, int));
347 #endif
348 extern _IO_ssize_t _IO_default_write __P ((_IO_FILE *, const void *,
349 _IO_ssize_t));
350 extern _IO_ssize_t _IO_default_read __P ((_IO_FILE *, void *, _IO_ssize_t));
351 extern int _IO_default_stat __P ((_IO_FILE *, void *));
352 #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
353 extern _IO_fpos64_t _IO_default_seek __P ((_IO_FILE *, _IO_off64_t, int));
354 #else
355 extern _IO_fpos_t _IO_default_seek __P ((_IO_FILE *, _IO_off_t, int));
356 #endif
357 extern int _IO_default_sync __P ((_IO_FILE *));
358 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
360 extern struct _IO_jump_t _IO_file_jumps;
361 extern struct _IO_jump_t _IO_streambuf_jumps;
362 extern struct _IO_jump_t _IO_proc_jumps;
363 extern struct _IO_jump_t _IO_str_jumps;
364 extern int _IO_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
365 extern int _IO_flush_all __P ((void));
366 extern void _IO_cleanup __P ((void));
367 extern void _IO_flush_all_linebuffered __P ((void));
369 #define _IO_do_flush(_f) \
370 _IO_do_write(_f, (_f)->_IO_write_base, \
371 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
372 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
373 #define _IO_mask_flags(fp, f, mask) \
374 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
375 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
376 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
377 #define _IO_setp(__fp, __p, __ep) \
378 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr = __p, (__fp)->_IO_write_end = (__ep))
379 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
380 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
381 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
382 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
384 /* Jumptable functions for files. */
386 extern int _IO_file_doallocate __P ((_IO_FILE *));
387 extern _IO_FILE* _IO_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
388 #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
389 extern _IO_fpos64_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
390 extern _IO_fpos64_t _IO_file_seek __P ((_IO_FILE *, _IO_off64_t, int));
391 #else
392 extern _IO_fpos_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
393 extern _IO_fpos_t _IO_file_seek __P ((_IO_FILE *, _IO_off_t, int));
394 #endif
395 extern _IO_size_t _IO_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
396 extern int _IO_file_stat __P ((_IO_FILE *, void *));
397 extern int _IO_file_close __P ((_IO_FILE *));
398 extern int _IO_file_underflow __P ((_IO_FILE *));
399 extern int _IO_file_overflow __P ((_IO_FILE *, int));
400 #define _IO_file_is_open(__fp) ((__fp)->_fileno >= 0)
401 extern void _IO_file_init __P ((_IO_FILE *));
402 extern _IO_FILE* _IO_file_attach __P ((_IO_FILE *, int));
403 extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int,
404 int, int));
405 #if _G_IO_IO_FILE_VERSION == 0x20001
406 extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *,
407 int));
408 #else
409 extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *));
410 #endif
411 extern _IO_ssize_t _IO_file_write __P ((_IO_FILE *, const void *,
412 _IO_ssize_t));
413 extern _IO_ssize_t _IO_file_read __P ((_IO_FILE *, void *, _IO_ssize_t));
414 extern int _IO_file_sync __P ((_IO_FILE *));
415 extern int _IO_file_close_it __P ((_IO_FILE *));
416 extern void _IO_file_finish __P ((_IO_FILE *, int));
418 /* Jumptable functions for proc_files. */
419 extern _IO_FILE* _IO_proc_open __P ((_IO_FILE *, const char *, const char *));
420 extern int _IO_proc_close __P ((_IO_FILE *));
422 /* Jumptable functions for strfiles. */
423 extern int _IO_str_underflow __P ((_IO_FILE *));
424 extern int _IO_str_overflow __P ((_IO_FILE *, int));
425 extern int _IO_str_pbackfail __P ((_IO_FILE *, int));
426 #if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
427 extern _IO_fpos64_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
428 #else
429 extern _IO_fpos_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off_t, int, int));
430 #endif
431 extern void _IO_str_finish __P ((_IO_FILE *, int));
433 /* Other strfile functions */
434 extern void _IO_str_init_static __P ((_IO_FILE *, char *, int, char *));
435 extern void _IO_str_init_readonly __P ((_IO_FILE *, const char *, int));
436 extern _IO_ssize_t _IO_str_count __P ((_IO_FILE *));
438 extern int _IO_vasprintf __P ((char **result_ptr, __const char *format,
439 _IO_va_list args));
440 extern int _IO_vdprintf __P ((int d, __const char *format, _IO_va_list arg));
441 extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen,
442 __const char *format, _IO_va_list args));
445 extern _IO_size_t _IO_getline __P ((_IO_FILE *,char *, _IO_size_t, int, int));
446 extern _IO_size_t _IO_getline_info __P ((_IO_FILE *,char *, _IO_size_t,
447 int, int, int *));
448 extern _IO_ssize_t _IO_getdelim __P ((char **, _IO_size_t *, int, _IO_FILE *));
449 extern double _IO_strtod __P ((const char *, char **));
450 extern char *_IO_dtoa __P ((double __d, int __mode, int __ndigits,
451 int *__decpt, int *__sign, char **__rve));
452 extern int _IO_outfloat __P ((double __value, _IO_FILE *__sb, int __type,
453 int __width, int __precision, int __flags,
454 int __sign_mode, int __fill));
456 extern _IO_FILE *_IO_list_all;
457 extern void (*_IO_cleanup_registration_needed) __PMT ((void));
459 #ifndef EOF
460 # define EOF (-1)
461 #endif
462 #ifndef NULL
463 # if defined __GNUG__ && \
464 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
465 # define NULL (__null)
466 # else
467 # if !defined(__cplusplus)
468 # define NULL ((void*)0)
469 # else
470 # define NULL (0)
471 # endif
472 # endif
473 #endif
475 #if _G_HAVE_MMAP
477 # include <unistd.h>
478 # include <fcntl.h>
479 # include <sys/mman.h>
480 # include <sys/param.h>
482 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
483 # define MAP_ANONYMOUS MAP_ANON
484 # endif
486 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
487 # undef _G_HAVE_MMAP
488 # define _G_HAVE_MMAP 0
489 # endif
491 #endif /* _G_HAVE_MMAP */
493 #if _G_HAVE_MMAP
495 # ifdef _LIBC
496 /* When using this code in the GNU libc we must not pollute the name space. */
497 # define mmap __mmap
498 # define munmap __munmap
499 # endif
501 # define ROUND_TO_PAGE(_S) \
502 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
504 # define FREE_BUF(_B, _S) \
505 munmap ((_B), ROUND_TO_PAGE (_S))
506 # define ALLOC_BUF(_B, _S, _R) \
507 do { \
508 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
509 PROT_READ | PROT_WRITE, \
510 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
511 if ((_B) == (char *) -1) \
512 return (_R); \
513 } while (0)
515 #else /* _G_HAVE_MMAP */
517 # define FREE_BUF(_B, _S) \
518 free(_B)
519 # define ALLOC_BUF(_B, _S, _R) \
520 do { \
521 (_B) = (char*)malloc(_S); \
522 if ((_B) == NULL) \
523 return (_R); \
524 } while (0)
526 #endif /* _G_HAVE_MMAP */
528 #ifndef OS_FSTAT
529 # define OS_FSTAT fstat
530 #endif
531 struct stat;
532 extern _IO_ssize_t _IO_read __P ((int, void *, _IO_size_t));
533 extern _IO_ssize_t _IO_write __P ((int, const void *, _IO_size_t));
534 extern _IO_off_t _IO_lseek __P ((int, _IO_off_t, int));
535 extern int _IO_close __P ((int));
536 extern int _IO_fstat __P ((int, struct stat *));
537 extern int _IO_vscanf __P ((const char *, _IO_va_list));
539 /* Operations on _IO_fpos_t.
540 Normally, these are trivial, but we provide hooks for configurations
541 where an _IO_fpos_t is a struct.
542 Note that _IO_off_t must be an integral type. */
544 /* _IO_pos_BAD is an _IO_fpos_t value indicating error, unknown, or EOF. */
545 #ifndef _IO_pos_BAD
546 # if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
547 # define _IO_pos_BAD ((_IO_fpos64_t) -1)
548 # else
549 # define _IO_pos_BAD ((_IO_fpos_t) -1)
550 # endif
551 #endif
552 /* _IO_pos_as_off converts an _IO_fpos_t value to an _IO_off_t value. */
553 #ifndef _IO_pos_as_off
554 # if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
555 # define _IO_pos_as_off(__pos) ((_IO_off64_t) (__pos))
556 # else
557 # define _IO_pos_as_off(__pos) ((_IO_off_t) (__pos))
558 # endif
559 #endif
560 /* _IO_pos_adjust adjust an _IO_fpos_t by some number of bytes. */
561 #ifndef _IO_pos_adjust
562 # define _IO_pos_adjust(__pos, __delta) ((__pos) += (__delta))
563 #endif
564 /* _IO_pos_0 is an _IO_fpos_t value indicating beginning of file. */
565 #ifndef _IO_pos_0
566 # if defined(_G_IO_IO_FILE_VERSION) && _G_IO_IO_FILE_VERSION == 0x20001
567 # define _IO_pos_0 ((_IO_fpos64_t) 0)
568 # else
569 # define _IO_pos_0 ((_IO_fpos_t) 0)
570 # endif
571 #endif
573 #ifdef __cplusplus
575 #endif
577 #ifdef _IO_MTSAFE_IO
578 /* check following! */
579 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
580 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
581 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
582 0, 0, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
583 #else
584 /* check following! */
585 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD) \
586 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
587 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD }
588 #endif
590 /* VTABLE_LABEL defines NAME as of the CLASS class.
591 CNLENGTH is strlen(#CLASS). */
592 #ifdef __GNUC__
593 # if _G_VTABLE_LABEL_HAS_LENGTH
594 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
595 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CNLENGTH #CLASS);
596 # else
597 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
598 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CLASS);
599 # endif
600 #endif /* __GNUC__ */
602 #if !defined(builtinbuf_vtable) && defined(__cplusplus)
603 # ifdef __GNUC__
604 VTABLE_LABEL(builtinbuf_vtable, builtinbuf, 10)
605 # else
606 # if _G_VTABLE_LABEL_HAS_LENGTH
607 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
608 # else
609 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
610 # endif
611 # endif
612 #endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
614 #if defined(__STDC__) || defined(__cplusplus)
615 # define _IO_va_start(args, last) va_start(args, last)
616 #else
617 # define _IO_va_start(args, last) va_start(args)
618 #endif
620 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
622 #if 1
623 # define COERCE_FILE(FILE) /* Nothing */
624 #else
625 /* This is part of the kludge for binary compatibility with old stdio. */
626 # define COERCE_FILE(FILE) \
627 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
628 && (FILE) = *(FILE**)&((int*)fp)[1])
629 #endif
631 #ifdef EINVAL
632 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
633 #else
634 # define MAYBE_SET_EINVAL /* nothing */
635 #endif
637 #ifdef IO_DEBUG
638 # define CHECK_FILE(FILE, RET) \
639 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
640 else { COERCE_FILE(FILE); \
641 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
642 { MAYBE_SET_EINVAL; return RET; }}
643 #else
644 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
645 #endif