1 /* Copyright (C) 1993, 1997, 1998, 1999 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,
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. */
28 # define __set_errno(Val) errno = (Val)
30 #if defined __GLIBC__ && __GLIBC__ >= 2
31 # include <bits/libc-lock.h>
33 /*# include <comthread.h>*/
42 #define _IO_seek_set 0
43 #define _IO_seek_cur 1
44 #define _IO_seek_end 2
46 /* THE JUMPTABLE FUNCTIONS.
48 * The _IO_FILE type is used to implement the FILE type in GNU libc,
49 * as well as the streambuf class in GNU iostreams for C++.
50 * These are all the same, just used differently.
51 * An _IO_FILE (or FILE) object is allows followed by a pointer to
52 * a jump table (of pointers to functions). The pointer is accessed
53 * with the _IO_JUMPS macro. The jump table has a eccentric format,
54 * so as to be compatible with the layout of a C++ virtual function table.
55 * (as implemented by g++). When a pointer to a streambuf object is
56 * coerced to an (_IO_FILE*), then _IO_JUMPS on the result just
57 * happens to point to the virtual function table of the streambuf.
58 * Thus the _IO_JUMPS function table used for C stdio/libio does
59 * double duty as the virtual function table for C++ streambuf.
61 * The entries in the _IO_JUMPS function table (and hence also the
62 * virtual functions of a streambuf) are described below.
63 * The first parameter of each function entry is the _IO_FILE/streambuf
64 * object being acted on (i.e. the 'this' parameter).
67 #if (!defined _IO_USE_OLD_IO_FILE \
68 && (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0))
69 # define _IO_JUMPS_OFFSET 1
72 #define _IO_JUMPS(THIS) ((struct _IO_FILE_plus *) (THIS))->vtable
73 #define _IO_WIDE_JUMPS(THIS) ((struct _IO_FILE *) (THIS))->_wide_data->_wide_vtable
75 # define _IO_JUMPS_FUNC(THIS) \
76 (*(struct _IO_jump_t **) ((void *) &((struct _IO_FILE_plus *) (THIS))->vtable\
77 + (THIS)->_vtable_offset))
79 # define _IO_JUMPS_FUNC(THIS) _IO_JUMPS(THIS)
81 #ifdef _G_USING_THUNKS
82 # define JUMP_FIELD(TYPE, NAME) TYPE NAME
83 # define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC (THIS)
84 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1)
85 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1, X2)
86 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1,X2, X3)
87 # define JUMP_INIT(NAME, VALUE) VALUE
88 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
90 /* These macros will change when we re-implement vtables to use "thunks"! */
91 # define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME
92 # define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
93 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
94 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
95 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
96 # define JUMP_INIT(NAME, VALUE) {0, 0, VALUE}
97 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0)
100 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
101 It does not delete (free) it, but does everything else to finalize it.
102 It matches the streambuf::~streambuf virtual destructor. */
103 typedef void (*_IO_finish_t
) __PMT ((_IO_FILE
*, int)); /* finalize */
104 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
106 /* The 'overflow' hook flushes the buffer.
107 The second argument is a character, or EOF.
108 It matches the streambuf::overflow virtual function. */
109 typedef int (*_IO_overflow_t
) __PMT ((_IO_FILE
*, int));
110 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
112 /* The 'underflow' hook tries to fills the get buffer.
113 It returns the next character (as an unsigned char) or EOF. The next
114 character remains in the get buffer, and the get position is not changed.
115 It matches the streambuf::underflow virtual function. */
116 typedef int (*_IO_underflow_t
) __PMT ((_IO_FILE
*));
117 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
119 /* The 'uflow' hook returns the next character in the input stream
120 (cast to unsigned char), and increments the read position;
121 EOF is returned on failure.
122 It matches the streambuf::uflow virtual function, which is not in the
123 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
124 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
126 /* The 'pbackfail' hook handles backing up.
127 It matches the streambuf::pbackfail virtual function. */
128 typedef int (*_IO_pbackfail_t
) __PMT ((_IO_FILE
*, int));
129 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
131 /* The 'xsputn' hook writes upto N characters from buffer DATA.
132 Returns the number of character actually written.
133 It matches the streambuf::xsputn virtual function. */
134 typedef _IO_size_t (*_IO_xsputn_t
) __PMT ((_IO_FILE
*FP
, const void *DATA
,
136 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
138 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
139 Returns the number of character actually read.
140 It matches the streambuf::xsgetn virtual function. */
141 typedef _IO_size_t (*_IO_xsgetn_t
) __PMT ((_IO_FILE
*FP
, void *DATA
,
143 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
145 /* The 'seekoff' hook moves the stream position to a new position
146 relative to the start of the file (if DIR==0), the current position
147 (MODE==1), or the end of the file (MODE==2).
148 It matches the streambuf::seekoff virtual function.
149 It is also used for the ANSI fseek function. */
150 typedef _IO_off64_t (*_IO_seekoff_t
) __PMT ((_IO_FILE
*FP
, _IO_off64_t OFF
,
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 fpos64_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 typedef _IO_off64_t (*_IO_seekpos_t
) __PMT ((_IO_FILE
*, _IO_off64_t
, int));
160 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
162 /* The 'setbuf' hook gives a buffer to the file.
163 It matches the streambuf::setbuf virtual function. */
164 typedef _IO_FILE
* (*_IO_setbuf_t
) __PMT ((_IO_FILE
*, char *, _IO_ssize_t
));
165 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
167 /* The 'sync' hook attempts to synchronize the internal data structures
168 of the file with the external state.
169 It matches the streambuf::sync virtual function. */
170 typedef int (*_IO_sync_t
) __PMT ((_IO_FILE
*));
171 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
173 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
174 It matches the streambuf::doallocate virtual function, which is not
175 in the ANSI/ISO C++ standard, but is part traditional implementations. */
176 typedef int (*_IO_doallocate_t
) __PMT ((_IO_FILE
*));
177 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
179 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
180 sysstat) are low-level hooks specific to this implementation.
181 There is no correspondence in the ANSI/ISO C++ standard library.
182 The hooks basically correspond to the Unix system functions
183 (read, write, close, lseek, and stat) except that a _IO_FILE*
184 parameter is used instead of a integer file descriptor; the default
185 implementation used for normal files just calls those functions.
186 The advantage of overriding these functions instead of the higher-level
187 ones (underflow, overflow etc) is that you can leave all the buffering
188 higher-level functions. */
190 /* The 'sysread' hook is used to read data from the external file into
191 an existing buffer. It generalizes the Unix read(2) function.
192 It matches the streambuf::sys_read virtual function, which is
193 specific to this implementation. */
194 typedef _IO_ssize_t (*_IO_read_t
) __PMT ((_IO_FILE
*, void *, _IO_ssize_t
));
195 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
197 /* The 'syswrite' hook is used to write data from an existing buffer
198 to an external file. It generalizes the Unix write(2) function.
199 It matches the streambuf::sys_write virtual function, which is
200 specific to this implementation. */
201 typedef _IO_ssize_t (*_IO_write_t
) __PMT ((_IO_FILE
*, const void *,
203 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
205 /* The 'sysseek' hook is used to re-position an external file.
206 It generalizes the Unix lseek(2) function.
207 It matches the streambuf::sys_seek virtual function, which is
208 specific to this implementation. */
209 typedef _IO_off64_t (*_IO_seek_t
) __PMT ((_IO_FILE
*, _IO_off64_t
, int));
210 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
212 /* The 'sysclose' hook is used to finalize (close, finish up) an
213 external file. It generalizes the Unix close(2) function.
214 It matches the streambuf::sys_close virtual function, which is
215 specific to this implementation. */
216 typedef int (*_IO_close_t
) __PMT ((_IO_FILE
*)); /* finalize */
217 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
219 /* The 'sysstat' hook is used to get information about an external file
220 into a struct stat buffer. It generalizes the Unix fstat(2) call.
221 It matches the streambuf::sys_stat virtual function, which is
222 specific to this implementation. */
223 typedef int (*_IO_stat_t
) __PMT ((_IO_FILE
*, void *));
224 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
226 /* The 'showmany' hook can be used to get an image how much input is
227 available. In many cases the answer will be 0 which means unknown
228 but some cases one can provide real information. */
229 typedef int (*_IO_showmanyc_t
) __PMT ((_IO_FILE
*));
230 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
232 /* The 'imbue' hook is used to get information about the currently
233 installed locales. */
234 typedef void (*_IO_imbue_t
) __PMT ((_IO_FILE
*, void *));
235 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
238 #define _IO_CHAR_TYPE char /* unsigned char ? */
239 #define _IO_INT_TYPE int
243 JUMP_FIELD(_G_size_t
, __dummy
);
244 #ifdef _G_USING_THUNKS
245 JUMP_FIELD(_G_size_t
, __dummy2
);
247 JUMP_FIELD(_IO_finish_t
, __finish
);
248 JUMP_FIELD(_IO_overflow_t
, __overflow
);
249 JUMP_FIELD(_IO_underflow_t
, __underflow
);
250 JUMP_FIELD(_IO_underflow_t
, __uflow
);
251 JUMP_FIELD(_IO_pbackfail_t
, __pbackfail
);
253 JUMP_FIELD(_IO_xsputn_t
, __xsputn
);
254 JUMP_FIELD(_IO_xsgetn_t
, __xsgetn
);
255 JUMP_FIELD(_IO_seekoff_t
, __seekoff
);
256 JUMP_FIELD(_IO_seekpos_t
, __seekpos
);
257 JUMP_FIELD(_IO_setbuf_t
, __setbuf
);
258 JUMP_FIELD(_IO_sync_t
, __sync
);
259 JUMP_FIELD(_IO_doallocate_t
, __doallocate
);
260 JUMP_FIELD(_IO_read_t
, __read
);
261 JUMP_FIELD(_IO_write_t
, __write
);
262 JUMP_FIELD(_IO_seek_t
, __seek
);
263 JUMP_FIELD(_IO_close_t
, __close
);
264 JUMP_FIELD(_IO_stat_t
, __stat
);
265 JUMP_FIELD(_IO_showmanyc_t
, __showmanyc
);
266 JUMP_FIELD(_IO_imbue_t
, __imbue
);
273 /* We always allocate an extra word following an _IO_FILE.
274 This contains a pointer to the function jump table used.
275 This is for compatibility with C++ streambuf; the word can
276 be used to smash to a pointer to a virtual function table. */
281 const struct _IO_jump_t
*vtable
;
284 /* Generic functions */
286 extern void _IO_switch_to_main_get_area
__P ((_IO_FILE
*));
287 extern void _IO_switch_to_backup_area
__P ((_IO_FILE
*));
288 extern int _IO_switch_to_get_mode
__P ((_IO_FILE
*));
289 extern void _IO_init
__P ((_IO_FILE
*, int));
290 extern int _IO_sputbackc
__P ((_IO_FILE
*, int));
291 extern int _IO_sungetc
__P ((_IO_FILE
*));
292 extern void _IO_un_link
__P ((_IO_FILE
*));
293 extern void _IO_link_in
__P ((_IO_FILE
*));
294 extern void _IO_doallocbuf
__P ((_IO_FILE
*));
295 extern void _IO_unsave_markers
__P ((_IO_FILE
*));
296 extern void _IO_setb
__P ((_IO_FILE
*, char *, char *, int));
297 extern unsigned _IO_adjust_column
__P ((unsigned, const char *, int));
298 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
300 extern void _IO_switch_to_main_wget_area
__P ((_IO_FILE
*));
301 extern void _IO_switch_to_wbackup_area
__P ((_IO_FILE
*));
302 extern int _IO_switch_to_wget_mode
__P ((_IO_FILE
*));
303 extern void _IO_wsetb
__P ((_IO_FILE
*, wchar_t *, wchar_t *, int));
304 extern wint_t _IO_sputbackwc
__P ((_IO_FILE
*, wint_t));
305 extern wint_t _IO_sungetwc
__P ((_IO_FILE
*));
306 extern void _IO_wdoallocbuf
__P ((_IO_FILE
*));
307 extern void _IO_unsave_wmarkers
__P ((_IO_FILE
*));
308 extern void _IO_wsetb
__P ((_IO_FILE
*, wchar_t *, wchar_t *, int));
309 extern unsigned _IO_adjust_wcolumn
__P ((unsigned, const wchar_t *, int));
311 /* Marker-related function. */
313 extern void _IO_init_marker
__P ((struct _IO_marker
*, _IO_FILE
*));
314 extern void _IO_init_wmarker
__P ((struct _IO_marker
*, _IO_FILE
*));
315 extern void _IO_remove_marker
__P ((struct _IO_marker
*));
316 extern int _IO_marker_difference
__P ((struct _IO_marker
*,
317 struct _IO_marker
*));
318 extern int _IO_marker_delta
__P ((struct _IO_marker
*));
319 extern int _IO_wmarker_delta
__P ((struct _IO_marker
*));
320 extern int _IO_seekmark
__P ((_IO_FILE
*, struct _IO_marker
*, int));
321 extern int _IO_seekwmark
__P ((_IO_FILE
*, struct _IO_marker
*, int));
323 /* Default jumptable functions. */
325 extern int _IO_default_underflow
__P ((_IO_FILE
*));
326 extern int _IO_default_uflow
__P ((_IO_FILE
*));
327 extern wint_t _IO_wdefault_uflow
__P ((_IO_FILE
*));
328 extern int _IO_default_doallocate
__P ((_IO_FILE
*));
329 extern int _IO_wdefault_doallocate
__P ((_IO_FILE
*));
330 extern void _IO_default_finish
__P ((_IO_FILE
*, int));
331 extern void _IO_wdefault_finish
__P ((_IO_FILE
*, int));
332 extern int _IO_default_pbackfail
__P ((_IO_FILE
*, int));
333 extern wint_t _IO_wdefault_pbackfail
__P ((_IO_FILE
*, wint_t));
334 extern _IO_FILE
* _IO_default_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
335 extern _IO_FILE
* _IO_wdefault_setbuf
__P ((_IO_FILE
*, wchar_t *,
337 extern _IO_size_t _IO_default_xsputn
__P ((_IO_FILE
*, const void *,
339 extern _IO_size_t _IO_wdefault_xsputn
__P ((_IO_FILE
*, const void *,
341 extern _IO_size_t _IO_default_xsgetn
__P ((_IO_FILE
*, void *, _IO_size_t
));
342 extern _IO_size_t _IO_wdefault_xsgetn
__P ((_IO_FILE
*, void *, _IO_size_t
));
343 extern _IO_off64_t _IO_default_seekoff
__P ((_IO_FILE
*,
344 _IO_off64_t
, int, int));
345 extern _IO_off64_t _IO_default_seekpos
__P ((_IO_FILE
*, _IO_off64_t
, int));
346 extern _IO_ssize_t _IO_default_write
__P ((_IO_FILE
*, const void *,
348 extern _IO_ssize_t _IO_default_read
__P ((_IO_FILE
*, void *, _IO_ssize_t
));
349 extern int _IO_default_stat
__P ((_IO_FILE
*, void *));
350 extern _IO_off64_t _IO_default_seek
__P ((_IO_FILE
*, _IO_off64_t
, int));
351 extern int _IO_default_sync
__P ((_IO_FILE
*));
352 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
353 extern int _IO_default_showmanyc
__P ((_IO_FILE
*));
354 extern void _IO_default_imbue
__P ((_IO_FILE
*, void *));
356 extern struct _IO_jump_t _IO_file_jumps
;
357 extern struct _IO_jump_t _IO_wfile_jumps
;
358 extern struct _IO_jump_t _IO_old_file_jumps
;
359 extern struct _IO_jump_t _IO_streambuf_jumps
;
360 extern struct _IO_jump_t _IO_proc_jumps
;
361 extern struct _IO_jump_t _IO_old_proc_jumps
;
362 extern struct _IO_jump_t _IO_str_jumps
;
363 extern struct _IO_jump_t _IO_wstr_jumps
;
364 extern int _IO_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
365 extern int _IO_new_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
366 extern int _IO_old_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
367 extern int _IO_wdo_write
__P ((_IO_FILE
*, const wchar_t *, _IO_size_t
));
368 extern int _IO_flush_all
__P ((void));
369 extern int _IO_cleanup
__P ((void));
370 extern void _IO_flush_all_linebuffered
__P ((void));
371 extern int _IO_new_fgetpos
__P ((_IO_FILE
*, _IO_fpos_t
*));
372 extern int _IO_old_fgetpos
__P ((_IO_FILE
*, _IO_fpos_t
*));
373 extern int _IO_new_fsetpos
__P ((_IO_FILE
*, const _IO_fpos_t
*));
374 extern int _IO_old_fsetpos
__P ((_IO_FILE
*, const _IO_fpos_t
*));
375 extern int _IO_new_fgetpos64
__P ((_IO_FILE
*, _IO_fpos64_t
*));
376 extern int _IO_old_fgetpos64
__P ((_IO_FILE
*, _IO_fpos64_t
*));
377 extern int _IO_new_fsetpos64
__P ((_IO_FILE
*, const _IO_fpos64_t
*));
378 extern int _IO_old_fsetpos64
__P ((_IO_FILE
*, const _IO_fpos64_t
*));
381 #define _IO_do_flush(_f) \
383 ? _IO_do_write(_f, (_f)->_IO_write_base, \
384 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
385 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
386 ((_f)->_wide_data->_IO_write_ptr \
387 - (_f)->_wide_data->_IO_write_base)))
388 #define _IO_old_do_flush(_f) \
389 _IO_old_do_write(_f, (_f)->_IO_write_base, \
390 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
391 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
392 #define _IO_mask_flags(fp, f, mask) \
393 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
394 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
395 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
396 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
397 (fp)->_wide_data->_IO_read_ptr = (g), \
398 (fp)->_wide_data->_IO_read_end = (eg))
399 #define _IO_setp(__fp, __p, __ep) \
400 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
401 = __p, (__fp)->_IO_write_end = (__ep))
402 #define _IO_wsetp(__fp, __p, __ep) \
403 ((__fp)->_wide_data->_IO_write_base \
404 = (__fp)->_wide_data->_IO_write_ptr = __p, \
405 (__fp)->_wide_data->_IO_write_end = (__ep))
406 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
407 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
408 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
409 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
410 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
411 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
412 - (fp)->_wide_data->_IO_buf_base)
414 /* Jumptable functions for files. */
416 extern int _IO_file_doallocate
__P ((_IO_FILE
*));
417 extern _IO_FILE
* _IO_file_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
418 extern _IO_off64_t _IO_file_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
419 extern _IO_size_t _IO_file_xsputn
__P ((_IO_FILE
*, const void *, _IO_size_t
));
420 extern _IO_size_t _IO_file_xsgetn
__P ((_IO_FILE
*, void *, _IO_size_t
));
421 extern int _IO_file_stat
__P ((_IO_FILE
*, void *));
422 extern int _IO_file_close
__P ((_IO_FILE
*));
423 extern int _IO_file_underflow
__P ((_IO_FILE
*));
424 extern int _IO_file_overflow
__P ((_IO_FILE
*, int));
425 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
426 extern void _IO_file_init
__P ((_IO_FILE
*));
427 extern _IO_FILE
* _IO_file_attach
__P ((_IO_FILE
*, int));
428 extern _IO_FILE
* _IO_file_open
__P ((_IO_FILE
*, const char *, int, int,
430 extern _IO_FILE
* _IO_file_fopen
__P ((_IO_FILE
*, const char *, const char *,
432 extern _IO_ssize_t _IO_file_write
__P ((_IO_FILE
*, const void *,
434 extern _IO_ssize_t _IO_file_read
__P ((_IO_FILE
*, void *, _IO_ssize_t
));
435 extern int _IO_file_sync
__P ((_IO_FILE
*));
436 extern int _IO_file_close_it
__P ((_IO_FILE
*));
437 extern _IO_off64_t _IO_file_seek
__P ((_IO_FILE
*, _IO_off64_t
, int));
438 extern void _IO_file_finish
__P ((_IO_FILE
*, int));
440 extern _IO_FILE
* _IO_new_file_attach
__P ((_IO_FILE
*, int));
441 extern int _IO_new_file_close_it
__P ((_IO_FILE
*));
442 extern void _IO_new_file_finish
__P ((_IO_FILE
*, int));
443 extern _IO_FILE
* _IO_new_file_fopen
__P ((_IO_FILE
*, const char *, const char *,
445 extern void _IO_no_init
__P ((_IO_FILE
*, int, int, struct _IO_wide_data
*,
446 struct _IO_jump_t
*));
447 extern void _IO_new_file_init
__P ((_IO_FILE
*));
448 extern _IO_FILE
* _IO_new_file_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
449 extern int _IO_new_file_sync
__P ((_IO_FILE
*));
450 extern int _IO_new_file_underflow
__P ((_IO_FILE
*));
451 extern int _IO_new_file_overflow
__P ((_IO_FILE
*, int));
452 extern _IO_off64_t _IO_new_file_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
453 extern _IO_ssize_t _IO_new_file_write
__P ((_IO_FILE
*, const void *,
455 extern _IO_size_t _IO_new_file_xsputn
__P ((_IO_FILE
*, const void *, _IO_size_t
));
457 extern _IO_FILE
* _IO_old_file_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
458 extern _IO_off64_t _IO_old_file_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int,
460 extern _IO_size_t _IO_old_file_xsputn
__P ((_IO_FILE
*, const void *,
462 extern int _IO_old_file_underflow
__P ((_IO_FILE
*));
463 extern int _IO_old_file_overflow
__P ((_IO_FILE
*, int));
464 extern void _IO_old_file_init
__P ((_IO_FILE
*));
465 extern _IO_FILE
* _IO_old_file_attach
__P ((_IO_FILE
*, int));
466 extern _IO_FILE
* _IO_old_file_fopen
__P ((_IO_FILE
*, const char *,
468 extern _IO_ssize_t _IO_old_file_write
__P ((_IO_FILE
*, const void *,
470 extern int _IO_old_file_sync
__P ((_IO_FILE
*));
471 extern int _IO_old_file_close_it
__P ((_IO_FILE
*));
472 extern void _IO_old_file_finish
__P ((_IO_FILE
*, int));
474 extern int _IO_wfile_doallocate
__P ((_IO_FILE
*));
475 extern _IO_size_t _IO_wfile_xsputn
__P ((_IO_FILE
*, const void *,
477 extern _IO_FILE
* _IO_wfile_setbuf
__P ((_IO_FILE
*, wchar_t *, _IO_ssize_t
));
478 extern wint_t _IO_wfile_sync
__P ((_IO_FILE
*));
479 extern wint_t _IO_wfile_underflow
__P ((_IO_FILE
*));
480 extern wint_t _IO_wfile_overflow
__P ((_IO_FILE
*, wint_t));
481 extern _IO_off64_t _IO_wfile_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
483 /* Jumptable functions for proc_files. */
484 extern _IO_FILE
* _IO_proc_open
__P ((_IO_FILE
*, const char *, const char *));
485 extern _IO_FILE
* _IO_new_proc_open
__P ((_IO_FILE
*, const char *, const char *));
486 extern _IO_FILE
* _IO_old_proc_open
__P ((_IO_FILE
*, const char *, const char *));
487 extern int _IO_proc_close
__P ((_IO_FILE
*));
488 extern int _IO_new_proc_close
__P ((_IO_FILE
*));
489 extern int _IO_old_proc_close
__P ((_IO_FILE
*));
491 /* Jumptable functions for strfiles. */
492 extern int _IO_str_underflow
__P ((_IO_FILE
*));
493 extern int _IO_str_overflow
__P ((_IO_FILE
*, int));
494 extern int _IO_str_pbackfail
__P ((_IO_FILE
*, int));
495 extern _IO_off64_t _IO_str_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
496 extern void _IO_str_finish
__P ((_IO_FILE
*, int));
498 /* Other strfile functions */
499 extern void _IO_str_init_static
__P ((_IO_FILE
*, char *, int, char *));
500 extern void _IO_str_init_readonly
__P ((_IO_FILE
*, const char *, int));
501 extern _IO_ssize_t _IO_str_count
__P ((_IO_FILE
*));
503 /* And the wide character versions. */
504 extern void _IO_wstr_init_static
__P ((_IO_FILE
*, wchar_t *, int, wchar_t *));
505 extern void _IO_wstr_init_readonly
__P ((_IO_FILE
*, const char *, int));
506 extern _IO_ssize_t _IO_wstr_count
__P ((_IO_FILE
*));
507 extern _IO_wint_t _IO_wstr_overflow
__P ((_IO_FILE
*, _IO_wint_t
));
508 extern _IO_wint_t _IO_wstr_underflow
__P ((_IO_FILE
*));
509 extern _IO_off64_t _IO_wstr_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
510 extern _IO_wint_t _IO_wstr_pbackfail
__P ((_IO_FILE
*, _IO_wint_t
));
511 extern void _IO_wstr_finish
__P ((_IO_FILE
*, int));
513 extern int _IO_vasprintf
__P ((char **result_ptr
, __const
char *format
,
515 extern int _IO_vdprintf
__P ((int d
, __const
char *format
, _IO_va_list arg
));
516 extern int _IO_vsnprintf
__P ((char *string
, _IO_size_t maxlen
,
517 __const
char *format
, _IO_va_list args
));
520 extern _IO_size_t _IO_getline
__P ((_IO_FILE
*,char *, _IO_size_t
, int, int));
521 extern _IO_size_t _IO_getline_info
__P ((_IO_FILE
*,char *, _IO_size_t
,
523 extern _IO_ssize_t _IO_getdelim
__P ((char **, _IO_size_t
*, int, _IO_FILE
*));
524 extern _IO_size_t _IO_getwline
__P ((_IO_FILE
*,wchar_t *, _IO_size_t
, wint_t,
526 extern _IO_size_t _IO_getwline_info
__P ((_IO_FILE
*,wchar_t *, _IO_size_t
,
527 wint_t, int, wint_t *));
528 extern double _IO_strtod
__P ((const char *, char **));
529 extern char *_IO_dtoa
__P ((double __d
, int __mode
, int __ndigits
,
530 int *__decpt
, int *__sign
, char **__rve
));
531 extern int _IO_outfloat
__P ((double __value
, _IO_FILE
*__sb
, int __type
,
532 int __width
, int __precision
, int __flags
,
533 int __sign_mode
, int __fill
));
535 extern _IO_FILE
*_IO_list_all
;
536 extern void (*_IO_cleanup_registration_needed
) __PMT ((void));
542 # if defined __GNUG__ && \
543 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
544 # define NULL (__null)
546 # if !defined(__cplusplus)
547 # define NULL ((void*)0)
558 # include <sys/mman.h>
559 # include <sys/param.h>
561 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
562 # define MAP_ANONYMOUS MAP_ANON
565 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
567 # define _G_HAVE_MMAP 0
570 #endif /* _G_HAVE_MMAP */
575 /* When using this code in the GNU libc we must not pollute the name space. */
577 # define munmap __munmap
578 # define ftruncate __ftruncate
581 # define ROUND_TO_PAGE(_S) \
582 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
584 # define FREE_BUF(_B, _S) \
585 munmap ((_B), ROUND_TO_PAGE (_S))
586 # define ALLOC_BUF(_B, _S, _R) \
588 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
589 PROT_READ | PROT_WRITE, \
590 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
591 if ((_B) == (char *) MAP_FAILED) \
594 # define ALLOC_WBUF(_B, _S, _R) \
596 (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
597 PROT_READ | PROT_WRITE, \
598 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
599 if ((_B) == (wchar_t *) MAP_FAILED) \
603 #else /* _G_HAVE_MMAP */
605 # define FREE_BUF(_B, _S) \
607 # define ALLOC_BUF(_B, _S, _R) \
609 (_B) = (char*)malloc(_S); \
614 #endif /* _G_HAVE_MMAP */
617 # define OS_FSTAT fstat
620 extern _IO_ssize_t _IO_read
__P ((int, void *, _IO_size_t
));
621 extern _IO_ssize_t _IO_write
__P ((int, const void *, _IO_size_t
));
622 extern _IO_off64_t _IO_lseek
__P ((int, _IO_off64_t
, int));
623 extern int _IO_close
__P ((int));
624 extern int _IO_fstat
__P ((int, struct stat
*));
625 extern int _IO_vscanf
__P ((const char *, _IO_va_list
));
627 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
629 # define _IO_pos_BAD ((_IO_off64_t) -1)
631 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
632 #ifndef _IO_pos_adjust
633 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
635 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
637 # define _IO_pos_0 ((_IO_off64_t) 0)
645 /* check following! */
646 # ifdef _IO_USE_OLD_IO_FILE
647 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
648 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
649 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
650 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
652 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
653 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
654 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
655 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
659 # ifdef _IO_USE_OLD_IO_FILE
660 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
661 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
662 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, 0, _IO_pos_BAD }
664 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
665 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
666 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
667 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
672 /* VTABLE_LABEL defines NAME as of the CLASS class.
673 CNLENGTH is strlen(#CLASS). */
675 # if _G_VTABLE_LABEL_HAS_LENGTH
676 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
677 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CNLENGTH #CLASS);
679 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
680 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CLASS);
682 #endif /* __GNUC__ */
684 #if !defined(builtinbuf_vtable) && defined(__cplusplus)
686 VTABLE_LABEL(builtinbuf_vtable
, builtinbuf
, 10)
688 # if _G_VTABLE_LABEL_HAS_LENGTH
689 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
691 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
694 #endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
696 #if defined(__STDC__) || defined(__cplusplus)
697 # define _IO_va_start(args, last) va_start(args, last)
699 # define _IO_va_start(args, last) va_start(args)
702 extern struct _IO_fake_stdiobuf _IO_stdin_buf
, _IO_stdout_buf
, _IO_stderr_buf
;
705 # define COERCE_FILE(FILE) /* Nothing */
707 /* This is part of the kludge for binary compatibility with old stdio. */
708 # define COERCE_FILE(FILE) \
709 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
710 && (FILE) = *(FILE**)&((int*)fp)[1])
714 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
716 # define MAYBE_SET_EINVAL /* nothing */
720 # define CHECK_FILE(FILE, RET) \
721 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
722 else { COERCE_FILE(FILE); \
723 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
724 { MAYBE_SET_EINVAL; return RET; }}
726 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)