1 /* Copyright (C) 1993, 1997, 1998, 1999, 2000 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) (THIS)->vtable
73 #define _IO_WIDE_JUMPS(THIS) ((struct _IO_FILE *) (THIS))->_wide_data->_wide_vtable
74 #define _IO_CHECK_WIDE(THIS) (((struct _IO_FILE *) (THIS))->_wide_data != NULL)
77 # define _IO_JUMPS_FUNC(THIS) \
78 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS ((struct _IO_FILE_plus *) (THIS)) \
79 + (THIS)->_vtable_offset))
81 # define _IO_JUMPS_FUNC(THIS) _IO_JUMPS ((struct _IO_FILE_plus *) (THIS))
83 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
84 #ifdef _G_USING_THUNKS
85 # define JUMP_FIELD(TYPE, NAME) TYPE NAME
86 # define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC (THIS)
87 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1)
88 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1, X2)
89 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1,X2, X3)
90 # define JUMP_INIT(NAME, VALUE) VALUE
91 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
93 # define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS)
94 # define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS, X1)
95 # define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS, X1, X2)
96 # define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS, X1,X2, X3)
98 /* These macros will change when we re-implement vtables to use "thunks"! */
99 # define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME
100 # define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
101 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
102 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
103 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
104 # define JUMP_INIT(NAME, VALUE) {0, 0, VALUE}
105 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0)
107 # define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
108 # define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
109 # define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
110 # define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
113 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
114 It does not delete (free) it, but does everything else to finalize it.
115 It matches the streambuf::~streambuf virtual destructor. */
116 typedef void (*_IO_finish_t
) __PMT ((_IO_FILE
*, int)); /* finalize */
117 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
118 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
120 /* The 'overflow' hook flushes the buffer.
121 The second argument is a character, or EOF.
122 It matches the streambuf::overflow virtual function. */
123 typedef int (*_IO_overflow_t
) __PMT ((_IO_FILE
*, int));
124 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
125 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
127 /* The 'underflow' hook tries to fills the get buffer.
128 It returns the next character (as an unsigned char) or EOF. The next
129 character remains in the get buffer, and the get position is not changed.
130 It matches the streambuf::underflow virtual function. */
131 typedef int (*_IO_underflow_t
) __PMT ((_IO_FILE
*));
132 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
133 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
135 /* The 'uflow' hook returns the next character in the input stream
136 (cast to unsigned char), and increments the read position;
137 EOF is returned on failure.
138 It matches the streambuf::uflow virtual function, which is not in the
139 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
140 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
141 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
143 /* The 'pbackfail' hook handles backing up.
144 It matches the streambuf::pbackfail virtual function. */
145 typedef int (*_IO_pbackfail_t
) __PMT ((_IO_FILE
*, int));
146 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
147 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
149 /* The 'xsputn' hook writes upto N characters from buffer DATA.
150 Returns the number of character actually written.
151 It matches the streambuf::xsputn virtual function. */
152 typedef _IO_size_t (*_IO_xsputn_t
) __PMT ((_IO_FILE
*FP
, const void *DATA
,
154 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
155 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
157 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
158 Returns the number of character actually read.
159 It matches the streambuf::xsgetn virtual function. */
160 typedef _IO_size_t (*_IO_xsgetn_t
) __PMT ((_IO_FILE
*FP
, void *DATA
,
162 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
163 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
165 /* The 'seekoff' hook moves the stream position to a new position
166 relative to the start of the file (if DIR==0), the current position
167 (MODE==1), or the end of the file (MODE==2).
168 It matches the streambuf::seekoff virtual function.
169 It is also used for the ANSI fseek function. */
170 typedef _IO_off64_t (*_IO_seekoff_t
) __PMT ((_IO_FILE
*FP
, _IO_off64_t OFF
,
172 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
173 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
175 /* The 'seekpos' hook also moves the stream position,
176 but to an absolute position given by a fpos64_t (seekpos).
177 It matches the streambuf::seekpos virtual function.
178 It is also used for the ANSI fgetpos and fsetpos functions. */
179 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
180 typedef _IO_off64_t (*_IO_seekpos_t
) __PMT ((_IO_FILE
*, _IO_off64_t
, int));
181 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
182 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
184 /* The 'setbuf' hook gives a buffer to the file.
185 It matches the streambuf::setbuf virtual function. */
186 typedef _IO_FILE
* (*_IO_setbuf_t
) __PMT ((_IO_FILE
*, char *, _IO_ssize_t
));
187 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
188 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
190 /* The 'sync' hook attempts to synchronize the internal data structures
191 of the file with the external state.
192 It matches the streambuf::sync virtual function. */
193 typedef int (*_IO_sync_t
) __PMT ((_IO_FILE
*));
194 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
195 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
197 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
198 It matches the streambuf::doallocate virtual function, which is not
199 in the ANSI/ISO C++ standard, but is part traditional implementations. */
200 typedef int (*_IO_doallocate_t
) __PMT ((_IO_FILE
*));
201 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
202 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
204 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
205 sysstat) are low-level hooks specific to this implementation.
206 There is no correspondence in the ANSI/ISO C++ standard library.
207 The hooks basically correspond to the Unix system functions
208 (read, write, close, lseek, and stat) except that a _IO_FILE*
209 parameter is used instead of a integer file descriptor; the default
210 implementation used for normal files just calls those functions.
211 The advantage of overriding these functions instead of the higher-level
212 ones (underflow, overflow etc) is that you can leave all the buffering
213 higher-level functions. */
215 /* The 'sysread' hook is used to read data from the external file into
216 an existing buffer. It generalizes the Unix read(2) function.
217 It matches the streambuf::sys_read virtual function, which is
218 specific to this implementation. */
219 typedef _IO_ssize_t (*_IO_read_t
) __PMT ((_IO_FILE
*, void *, _IO_ssize_t
));
220 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
221 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
223 /* The 'syswrite' hook is used to write data from an existing buffer
224 to an external file. It generalizes the Unix write(2) function.
225 It matches the streambuf::sys_write virtual function, which is
226 specific to this implementation. */
227 typedef _IO_ssize_t (*_IO_write_t
) __PMT ((_IO_FILE
*, const void *,
229 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
230 #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
232 /* The 'sysseek' hook is used to re-position an external file.
233 It generalizes the Unix lseek(2) function.
234 It matches the streambuf::sys_seek virtual function, which is
235 specific to this implementation. */
236 typedef _IO_off64_t (*_IO_seek_t
) __PMT ((_IO_FILE
*, _IO_off64_t
, int));
237 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
238 #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
240 /* The 'sysclose' hook is used to finalize (close, finish up) an
241 external file. It generalizes the Unix close(2) function.
242 It matches the streambuf::sys_close virtual function, which is
243 specific to this implementation. */
244 typedef int (*_IO_close_t
) __PMT ((_IO_FILE
*)); /* finalize */
245 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
246 #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
248 /* The 'sysstat' hook is used to get information about an external file
249 into a struct stat buffer. It generalizes the Unix fstat(2) call.
250 It matches the streambuf::sys_stat virtual function, which is
251 specific to this implementation. */
252 typedef int (*_IO_stat_t
) __PMT ((_IO_FILE
*, void *));
253 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
254 #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
256 /* The 'showmany' hook can be used to get an image how much input is
257 available. In many cases the answer will be 0 which means unknown
258 but some cases one can provide real information. */
259 typedef int (*_IO_showmanyc_t
) __PMT ((_IO_FILE
*));
260 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
261 #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
263 /* The 'imbue' hook is used to get information about the currently
264 installed locales. */
265 typedef void (*_IO_imbue_t
) __PMT ((_IO_FILE
*, void *));
266 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
267 #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
270 #define _IO_CHAR_TYPE char /* unsigned char ? */
271 #define _IO_INT_TYPE int
275 JUMP_FIELD(_G_size_t
, __dummy
);
276 #ifdef _G_USING_THUNKS
277 JUMP_FIELD(_G_size_t
, __dummy2
);
279 JUMP_FIELD(_IO_finish_t
, __finish
);
280 JUMP_FIELD(_IO_overflow_t
, __overflow
);
281 JUMP_FIELD(_IO_underflow_t
, __underflow
);
282 JUMP_FIELD(_IO_underflow_t
, __uflow
);
283 JUMP_FIELD(_IO_pbackfail_t
, __pbackfail
);
285 JUMP_FIELD(_IO_xsputn_t
, __xsputn
);
286 JUMP_FIELD(_IO_xsgetn_t
, __xsgetn
);
287 JUMP_FIELD(_IO_seekoff_t
, __seekoff
);
288 JUMP_FIELD(_IO_seekpos_t
, __seekpos
);
289 JUMP_FIELD(_IO_setbuf_t
, __setbuf
);
290 JUMP_FIELD(_IO_sync_t
, __sync
);
291 JUMP_FIELD(_IO_doallocate_t
, __doallocate
);
292 JUMP_FIELD(_IO_read_t
, __read
);
293 JUMP_FIELD(_IO_write_t
, __write
);
294 JUMP_FIELD(_IO_seek_t
, __seek
);
295 JUMP_FIELD(_IO_close_t
, __close
);
296 JUMP_FIELD(_IO_stat_t
, __stat
);
297 JUMP_FIELD(_IO_showmanyc_t
, __showmanyc
);
298 JUMP_FIELD(_IO_imbue_t
, __imbue
);
305 /* We always allocate an extra word following an _IO_FILE.
306 This contains a pointer to the function jump table used.
307 This is for compatibility with C++ streambuf; the word can
308 be used to smash to a pointer to a virtual function table. */
313 const struct _IO_jump_t
*vtable
;
316 /* Special file type for fopencookie function. */
317 struct _IO_cookie_file
319 struct _IO_FILE_plus __fp
;
321 _IO_cookie_io_functions_t __io_functions
;
324 /* Iterator type for walking global linked list of _IO_FILE objects. */
326 typedef struct _IO_FILE
*_IO_ITER
;
328 /* Generic functions */
330 extern void _IO_switch_to_main_get_area
__P ((_IO_FILE
*));
331 extern void _IO_switch_to_backup_area
__P ((_IO_FILE
*));
332 extern int _IO_switch_to_get_mode
__P ((_IO_FILE
*));
333 extern void _IO_init
__P ((_IO_FILE
*, int));
334 extern int _IO_sputbackc
__P ((_IO_FILE
*, int));
335 extern int _IO_sungetc
__P ((_IO_FILE
*));
336 extern void _IO_un_link
__P ((struct _IO_FILE_plus
*));
337 extern void _IO_link_in
__P ((struct _IO_FILE_plus
*));
338 extern void _IO_doallocbuf
__P ((_IO_FILE
*));
339 extern void _IO_unsave_markers
__P ((_IO_FILE
*));
340 extern void _IO_setb
__P ((_IO_FILE
*, char *, char *, int));
341 extern unsigned _IO_adjust_column
__P ((unsigned, const char *, int));
342 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
344 extern void _IO_switch_to_main_wget_area
__P ((_IO_FILE
*));
345 extern void _IO_switch_to_wbackup_area
__P ((_IO_FILE
*));
346 extern int _IO_switch_to_wget_mode
__P ((_IO_FILE
*));
347 extern void _IO_wsetb
__P ((_IO_FILE
*, wchar_t *, wchar_t *, int));
348 extern wint_t _IO_sputbackwc
__P ((_IO_FILE
*, wint_t));
349 extern wint_t _IO_sungetwc
__P ((_IO_FILE
*));
350 extern void _IO_wdoallocbuf
__P ((_IO_FILE
*));
351 extern void _IO_unsave_wmarkers
__P ((_IO_FILE
*));
352 extern unsigned _IO_adjust_wcolumn
__P ((unsigned, const wchar_t *, int));
354 /* Marker-related function. */
356 extern void _IO_init_marker
__P ((struct _IO_marker
*, _IO_FILE
*));
357 extern void _IO_init_wmarker
__P ((struct _IO_marker
*, _IO_FILE
*));
358 extern void _IO_remove_marker
__P ((struct _IO_marker
*));
359 extern int _IO_marker_difference
__P ((struct _IO_marker
*,
360 struct _IO_marker
*));
361 extern int _IO_marker_delta
__P ((struct _IO_marker
*));
362 extern int _IO_wmarker_delta
__P ((struct _IO_marker
*));
363 extern int _IO_seekmark
__P ((_IO_FILE
*, struct _IO_marker
*, int));
364 extern int _IO_seekwmark
__P ((_IO_FILE
*, struct _IO_marker
*, int));
366 /* Functions for iterating global list and dealing with
369 extern _IO_ITER _IO_iter_begin
__P ((void));
370 extern _IO_ITER _IO_iter_end
__P ((void));
371 extern _IO_ITER _IO_iter_next
__P ((_IO_ITER
));
372 extern _IO_FILE
*_IO_iter_file
__P ((_IO_ITER
));
373 extern void _IO_list_lock
__P ((void));
374 extern void _IO_list_unlock
__P ((void));
375 extern void _IO_list_resetlock
__P ((void));
377 /* Default jumptable functions. */
379 extern int _IO_default_underflow
__P ((_IO_FILE
*));
380 extern int _IO_default_uflow
__P ((_IO_FILE
*));
381 extern wint_t _IO_wdefault_uflow
__P ((_IO_FILE
*));
382 extern int _IO_default_doallocate
__P ((_IO_FILE
*));
383 extern int _IO_wdefault_doallocate
__P ((_IO_FILE
*));
384 extern void _IO_default_finish
__P ((_IO_FILE
*, int));
385 extern void _IO_wdefault_finish
__P ((_IO_FILE
*, int));
386 extern int _IO_default_pbackfail
__P ((_IO_FILE
*, int));
387 extern wint_t _IO_wdefault_pbackfail
__P ((_IO_FILE
*, wint_t));
388 extern _IO_FILE
* _IO_default_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
389 extern _IO_FILE
* _IO_wdefault_setbuf
__P ((_IO_FILE
*, wchar_t *,
391 extern _IO_size_t _IO_default_xsputn
__P ((_IO_FILE
*, const void *,
393 extern _IO_size_t _IO_wdefault_xsputn
__P ((_IO_FILE
*, const void *,
395 extern _IO_size_t _IO_default_xsgetn
__P ((_IO_FILE
*, void *, _IO_size_t
));
396 extern _IO_size_t _IO_wdefault_xsgetn
__P ((_IO_FILE
*, void *, _IO_size_t
));
397 extern _IO_off64_t _IO_default_seekoff
__P ((_IO_FILE
*,
398 _IO_off64_t
, int, int));
399 extern _IO_off64_t _IO_default_seekpos
__P ((_IO_FILE
*, _IO_off64_t
, int));
400 extern _IO_ssize_t _IO_default_write
__P ((_IO_FILE
*, const void *,
402 extern _IO_ssize_t _IO_default_read
__P ((_IO_FILE
*, void *, _IO_ssize_t
));
403 extern int _IO_default_stat
__P ((_IO_FILE
*, void *));
404 extern _IO_off64_t _IO_default_seek
__P ((_IO_FILE
*, _IO_off64_t
, int));
405 extern int _IO_default_sync
__P ((_IO_FILE
*));
406 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
407 extern int _IO_default_showmanyc
__P ((_IO_FILE
*));
408 extern void _IO_default_imbue
__P ((_IO_FILE
*, void *));
410 extern struct _IO_jump_t _IO_file_jumps
;
411 extern struct _IO_jump_t _IO_wfile_jumps
;
412 extern struct _IO_jump_t _IO_old_file_jumps
;
413 extern struct _IO_jump_t _IO_streambuf_jumps
;
414 extern struct _IO_jump_t _IO_proc_jumps
;
415 extern struct _IO_jump_t _IO_old_proc_jumps
;
416 extern struct _IO_jump_t _IO_str_jumps
;
417 extern struct _IO_jump_t _IO_wstr_jumps
;
418 extern struct _IO_codecvt __libio_codecvt
;
419 extern int _IO_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
420 extern int _IO_new_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
421 extern int _IO_old_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
422 extern int _IO_wdo_write
__P ((_IO_FILE
*, const wchar_t *, _IO_size_t
));
423 extern int _IO_flush_all
__P ((void));
424 extern int _IO_cleanup
__P ((void));
425 extern void _IO_flush_all_linebuffered
__P ((void));
426 extern int _IO_new_fgetpos
__P ((_IO_FILE
*, _IO_fpos_t
*));
427 extern int _IO_old_fgetpos
__P ((_IO_FILE
*, _IO_fpos_t
*));
428 extern int _IO_new_fsetpos
__P ((_IO_FILE
*, const _IO_fpos_t
*));
429 extern int _IO_old_fsetpos
__P ((_IO_FILE
*, const _IO_fpos_t
*));
430 extern int _IO_new_fgetpos64
__P ((_IO_FILE
*, _IO_fpos64_t
*));
431 extern int _IO_old_fgetpos64
__P ((_IO_FILE
*, _IO_fpos64_t
*));
432 extern int _IO_new_fsetpos64
__P ((_IO_FILE
*, const _IO_fpos64_t
*));
433 extern int _IO_old_fsetpos64
__P ((_IO_FILE
*, const _IO_fpos64_t
*));
436 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
437 # define _IO_do_flush(_f) \
439 ? _IO_do_write(_f, (_f)->_IO_write_base, \
440 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
441 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
442 ((_f)->_wide_data->_IO_write_ptr \
443 - (_f)->_wide_data->_IO_write_base)))
445 # define _IO_do_flush(_f) \
446 _IO_do_write(_f, (_f)->_IO_write_base, \
447 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
449 #define _IO_old_do_flush(_f) \
450 _IO_old_do_write(_f, (_f)->_IO_write_base, \
451 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
452 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
453 #define _IO_mask_flags(fp, f, mask) \
454 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
455 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
456 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
457 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
458 (fp)->_wide_data->_IO_read_ptr = (g), \
459 (fp)->_wide_data->_IO_read_end = (eg))
460 #define _IO_setp(__fp, __p, __ep) \
461 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
462 = __p, (__fp)->_IO_write_end = (__ep))
463 #define _IO_wsetp(__fp, __p, __ep) \
464 ((__fp)->_wide_data->_IO_write_base \
465 = (__fp)->_wide_data->_IO_write_ptr = __p, \
466 (__fp)->_wide_data->_IO_write_end = (__ep))
467 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
468 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
469 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
470 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
471 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
472 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
473 - (fp)->_wide_data->_IO_buf_base)
475 /* Jumptable functions for files. */
477 extern int _IO_file_doallocate
__P ((_IO_FILE
*));
478 extern _IO_FILE
* _IO_file_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
479 extern _IO_off64_t _IO_file_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
480 extern _IO_size_t _IO_file_xsputn
__P ((_IO_FILE
*, const void *, _IO_size_t
));
481 extern _IO_size_t _IO_file_xsgetn
__P ((_IO_FILE
*, void *, _IO_size_t
));
482 extern int _IO_file_stat
__P ((_IO_FILE
*, void *));
483 extern int _IO_file_close
__P ((_IO_FILE
*));
484 extern int _IO_file_underflow
__P ((_IO_FILE
*));
485 extern int _IO_file_overflow
__P ((_IO_FILE
*, int));
486 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
487 extern void _IO_file_init
__P ((struct _IO_FILE_plus
*));
488 extern _IO_FILE
* _IO_file_attach
__P ((_IO_FILE
*, int));
489 extern _IO_FILE
* _IO_file_open
__P ((_IO_FILE
*, const char *, int, int,
491 extern _IO_FILE
* _IO_file_fopen
__P ((_IO_FILE
*, const char *, const char *,
493 extern _IO_ssize_t _IO_file_write
__P ((_IO_FILE
*, const void *,
495 extern _IO_ssize_t _IO_file_read
__P ((_IO_FILE
*, void *, _IO_ssize_t
));
496 extern int _IO_file_sync
__P ((_IO_FILE
*));
497 extern int _IO_file_close_it
__P ((_IO_FILE
*));
498 extern _IO_off64_t _IO_file_seek
__P ((_IO_FILE
*, _IO_off64_t
, int));
499 extern void _IO_file_finish
__P ((_IO_FILE
*, int));
501 extern _IO_FILE
* _IO_new_file_attach
__P ((_IO_FILE
*, int));
502 extern int _IO_new_file_close_it
__P ((_IO_FILE
*));
503 extern void _IO_new_file_finish
__P ((_IO_FILE
*, int));
504 extern _IO_FILE
* _IO_new_file_fopen
__P ((_IO_FILE
*, const char *, const char *,
506 extern void _IO_no_init
__P ((_IO_FILE
*, int, int, struct _IO_wide_data
*,
507 struct _IO_jump_t
*));
508 extern void _IO_new_file_init
__P ((struct _IO_FILE_plus
*));
509 extern _IO_FILE
* _IO_new_file_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
510 extern int _IO_new_file_sync
__P ((_IO_FILE
*));
511 extern int _IO_new_file_underflow
__P ((_IO_FILE
*));
512 extern int _IO_new_file_overflow
__P ((_IO_FILE
*, int));
513 extern _IO_off64_t _IO_new_file_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
514 extern _IO_ssize_t _IO_new_file_write
__P ((_IO_FILE
*, const void *,
516 extern _IO_size_t _IO_new_file_xsputn
__P ((_IO_FILE
*, const void *, _IO_size_t
));
518 extern _IO_FILE
* _IO_old_file_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
519 extern _IO_off64_t _IO_old_file_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int,
521 extern _IO_size_t _IO_old_file_xsputn
__P ((_IO_FILE
*, const void *,
523 extern int _IO_old_file_underflow
__P ((_IO_FILE
*));
524 extern int _IO_old_file_overflow
__P ((_IO_FILE
*, int));
525 extern void _IO_old_file_init
__P ((struct _IO_FILE_plus
*));
526 extern _IO_FILE
* _IO_old_file_attach
__P ((_IO_FILE
*, int));
527 extern _IO_FILE
* _IO_old_file_fopen
__P ((_IO_FILE
*, const char *,
529 extern _IO_ssize_t _IO_old_file_write
__P ((_IO_FILE
*, const void *,
531 extern int _IO_old_file_sync
__P ((_IO_FILE
*));
532 extern int _IO_old_file_close_it
__P ((_IO_FILE
*));
533 extern void _IO_old_file_finish
__P ((_IO_FILE
*, int));
535 extern int _IO_wfile_doallocate
__P ((_IO_FILE
*));
536 extern _IO_size_t _IO_wfile_xsputn
__P ((_IO_FILE
*, const void *,
538 extern _IO_FILE
* _IO_wfile_setbuf
__P ((_IO_FILE
*, wchar_t *, _IO_ssize_t
));
539 extern wint_t _IO_wfile_sync
__P ((_IO_FILE
*));
540 extern wint_t _IO_wfile_underflow
__P ((_IO_FILE
*));
541 extern wint_t _IO_wfile_overflow
__P ((_IO_FILE
*, wint_t));
542 extern _IO_off64_t _IO_wfile_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
544 /* Jumptable functions for proc_files. */
545 extern _IO_FILE
* _IO_proc_open
__P ((_IO_FILE
*, const char *, const char *));
546 extern _IO_FILE
* _IO_new_proc_open
__P ((_IO_FILE
*, const char *, const char *));
547 extern _IO_FILE
* _IO_old_proc_open
__P ((_IO_FILE
*, const char *, const char *));
548 extern int _IO_proc_close
__P ((_IO_FILE
*));
549 extern int _IO_new_proc_close
__P ((_IO_FILE
*));
550 extern int _IO_old_proc_close
__P ((_IO_FILE
*));
552 /* Jumptable functions for strfiles. */
553 extern int _IO_str_underflow
__P ((_IO_FILE
*));
554 extern int _IO_str_overflow
__P ((_IO_FILE
*, int));
555 extern int _IO_str_pbackfail
__P ((_IO_FILE
*, int));
556 extern _IO_off64_t _IO_str_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
557 extern void _IO_str_finish
__P ((_IO_FILE
*, int));
559 /* Other strfile functions */
561 extern void _IO_str_init_static
__P ((struct _IO_strfile_
*, char *, int, char *));
562 extern void _IO_str_init_readonly
__P ((struct _IO_strfile_
*, const char *, int));
563 extern _IO_ssize_t _IO_str_count
__P ((_IO_FILE
*));
565 /* And the wide character versions. */
566 extern void _IO_wstr_init_static
__P ((_IO_FILE
*, wchar_t *, int, wchar_t *));
567 extern void _IO_wstr_init_readonly
__P ((_IO_FILE
*, const char *, int));
568 extern _IO_ssize_t _IO_wstr_count
__P ((_IO_FILE
*));
569 extern _IO_wint_t _IO_wstr_overflow
__P ((_IO_FILE
*, _IO_wint_t
));
570 extern _IO_wint_t _IO_wstr_underflow
__P ((_IO_FILE
*));
571 extern _IO_off64_t _IO_wstr_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
572 extern _IO_wint_t _IO_wstr_pbackfail
__P ((_IO_FILE
*, _IO_wint_t
));
573 extern void _IO_wstr_finish
__P ((_IO_FILE
*, int));
575 extern int _IO_vasprintf
__P ((char **result_ptr
, __const
char *format
,
577 extern int _IO_vdprintf
__P ((int d
, __const
char *format
, _IO_va_list arg
));
578 extern int _IO_vsnprintf
__P ((char *string
, _IO_size_t maxlen
,
579 __const
char *format
, _IO_va_list args
));
582 extern _IO_size_t _IO_getline
__P ((_IO_FILE
*,char *, _IO_size_t
, int, int));
583 extern _IO_size_t _IO_getline_info
__P ((_IO_FILE
*,char *, _IO_size_t
,
585 extern _IO_ssize_t _IO_getdelim
__P ((char **, _IO_size_t
*, int, _IO_FILE
*));
586 extern _IO_size_t _IO_getwline
__P ((_IO_FILE
*,wchar_t *, _IO_size_t
, wint_t,
588 extern _IO_size_t _IO_getwline_info
__P ((_IO_FILE
*,wchar_t *, _IO_size_t
,
589 wint_t, int, wint_t *));
590 extern double _IO_strtod
__P ((const char *, char **));
591 extern char *_IO_dtoa
__P ((double __d
, int __mode
, int __ndigits
,
592 int *__decpt
, int *__sign
, char **__rve
));
593 extern int _IO_outfloat
__P ((double __value
, _IO_FILE
*__sb
, int __type
,
594 int __width
, int __precision
, int __flags
,
595 int __sign_mode
, int __fill
));
597 extern struct _IO_FILE_plus
*_IO_list_all
;
598 extern void (*_IO_cleanup_registration_needed
) __PMT ((void));
604 # if defined __GNUG__ && \
605 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
606 # define NULL (__null)
608 # if !defined(__cplusplus)
609 # define NULL ((void*)0)
620 # include <sys/mman.h>
621 # include <sys/param.h>
623 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
624 # define MAP_ANONYMOUS MAP_ANON
627 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
629 # define _G_HAVE_MMAP 0
632 #endif /* _G_HAVE_MMAP */
637 /* When using this code in the GNU libc we must not pollute the name space. */
639 # define munmap __munmap
640 # define ftruncate __ftruncate
643 # define ROUND_TO_PAGE(_S) \
644 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
646 # define FREE_BUF(_B, _S) \
647 munmap ((_B), ROUND_TO_PAGE (_S))
648 # define ALLOC_BUF(_B, _S, _R) \
650 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
651 PROT_READ | PROT_WRITE, \
652 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
653 if ((_B) == (char *) MAP_FAILED) \
656 # define ALLOC_WBUF(_B, _S, _R) \
658 (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
659 PROT_READ | PROT_WRITE, \
660 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
661 if ((_B) == (wchar_t *) MAP_FAILED) \
665 #else /* _G_HAVE_MMAP */
667 # define FREE_BUF(_B, _S) \
669 # define ALLOC_BUF(_B, _S, _R) \
671 (_B) = (char*)malloc(_S); \
675 # define ALLOC_WBUF(_B, _S, _R) \
677 (_B) = (wchar_t *)malloc(_S); \
682 #endif /* _G_HAVE_MMAP */
685 # define OS_FSTAT fstat
688 extern _IO_ssize_t _IO_read
__P ((int, void *, _IO_size_t
));
689 extern _IO_ssize_t _IO_write
__P ((int, const void *, _IO_size_t
));
690 extern _IO_off64_t _IO_lseek
__P ((int, _IO_off64_t
, int));
691 extern int _IO_close
__P ((int));
692 extern int _IO_fstat
__P ((int, struct stat
*));
693 extern int _IO_vscanf
__P ((const char *, _IO_va_list
));
695 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
697 # define _IO_pos_BAD ((_IO_off64_t) -1)
699 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
700 #ifndef _IO_pos_adjust
701 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
703 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
705 # define _IO_pos_0 ((_IO_off64_t) 0)
713 /* check following! */
714 # ifdef _IO_USE_OLD_IO_FILE
715 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
716 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
717 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
718 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
720 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
721 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
722 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
723 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
724 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
727 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
728 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
729 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
730 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
735 # ifdef _IO_USE_OLD_IO_FILE
736 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
737 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
738 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
741 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
742 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
743 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
744 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
745 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
748 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
749 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
750 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
751 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
757 /* VTABLE_LABEL defines NAME as of the CLASS class.
758 CNLENGTH is strlen(#CLASS). */
760 # if _G_VTABLE_LABEL_HAS_LENGTH
761 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
762 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CNLENGTH #CLASS);
764 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
765 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CLASS);
767 #endif /* __GNUC__ */
769 #if !defined(builtinbuf_vtable) && defined(__cplusplus)
771 VTABLE_LABEL(builtinbuf_vtable
, builtinbuf
, 10)
773 # if _G_VTABLE_LABEL_HAS_LENGTH
774 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
776 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
779 #endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
781 #if defined(__STDC__) || defined(__cplusplus)
782 # define _IO_va_start(args, last) va_start(args, last)
784 # define _IO_va_start(args, last) va_start(args)
787 extern struct _IO_fake_stdiobuf _IO_stdin_buf
, _IO_stdout_buf
, _IO_stderr_buf
;
790 # define COERCE_FILE(FILE) /* Nothing */
792 /* This is part of the kludge for binary compatibility with old stdio. */
793 # define COERCE_FILE(FILE) \
794 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
795 && (FILE) = *(FILE**)&((int*)fp)[1])
799 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
801 # define MAYBE_SET_EINVAL /* nothing */
805 # define CHECK_FILE(FILE, RET) \
806 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
807 else { COERCE_FILE(FILE); \
808 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
809 { MAYBE_SET_EINVAL; return RET; }}
811 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)