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 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
82 #ifdef _G_USING_THUNKS
83 # define JUMP_FIELD(TYPE, NAME) TYPE NAME
84 # define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC (THIS)
85 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1)
86 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1, X2)
87 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1,X2, X3)
88 # define JUMP_INIT(NAME, VALUE) VALUE
89 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
91 # define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS)
92 # define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS, X1)
93 # define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS, X1, X2)
94 # define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC (THIS, X1,X2, X3)
96 /* These macros will change when we re-implement vtables to use "thunks"! */
97 # define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME
98 # define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
99 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
100 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
101 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
102 # define JUMP_INIT(NAME, VALUE) {0, 0, VALUE}
103 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0)
105 # define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
106 # define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
107 # define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
108 # define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
111 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
112 It does not delete (free) it, but does everything else to finalize it.
113 It matches the streambuf::~streambuf virtual destructor. */
114 typedef void (*_IO_finish_t
) __PMT ((_IO_FILE
*, int)); /* finalize */
115 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
116 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
118 /* The 'overflow' hook flushes the buffer.
119 The second argument is a character, or EOF.
120 It matches the streambuf::overflow virtual function. */
121 typedef int (*_IO_overflow_t
) __PMT ((_IO_FILE
*, int));
122 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
123 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
125 /* The 'underflow' hook tries to fills the get buffer.
126 It returns the next character (as an unsigned char) or EOF. The next
127 character remains in the get buffer, and the get position is not changed.
128 It matches the streambuf::underflow virtual function. */
129 typedef int (*_IO_underflow_t
) __PMT ((_IO_FILE
*));
130 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
131 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
133 /* The 'uflow' hook returns the next character in the input stream
134 (cast to unsigned char), and increments the read position;
135 EOF is returned on failure.
136 It matches the streambuf::uflow virtual function, which is not in the
137 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
138 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
139 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
141 /* The 'pbackfail' hook handles backing up.
142 It matches the streambuf::pbackfail virtual function. */
143 typedef int (*_IO_pbackfail_t
) __PMT ((_IO_FILE
*, int));
144 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
145 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
147 /* The 'xsputn' hook writes upto N characters from buffer DATA.
148 Returns the number of character actually written.
149 It matches the streambuf::xsputn virtual function. */
150 typedef _IO_size_t (*_IO_xsputn_t
) __PMT ((_IO_FILE
*FP
, const void *DATA
,
152 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
153 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
155 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
156 Returns the number of character actually read.
157 It matches the streambuf::xsgetn virtual function. */
158 typedef _IO_size_t (*_IO_xsgetn_t
) __PMT ((_IO_FILE
*FP
, void *DATA
,
160 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
161 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
163 /* The 'seekoff' hook moves the stream position to a new position
164 relative to the start of the file (if DIR==0), the current position
165 (MODE==1), or the end of the file (MODE==2).
166 It matches the streambuf::seekoff virtual function.
167 It is also used for the ANSI fseek function. */
168 typedef _IO_off64_t (*_IO_seekoff_t
) __PMT ((_IO_FILE
*FP
, _IO_off64_t OFF
,
170 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
171 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
173 /* The 'seekpos' hook also moves the stream position,
174 but to an absolute position given by a fpos64_t (seekpos).
175 It matches the streambuf::seekpos virtual function.
176 It is also used for the ANSI fgetpos and fsetpos functions. */
177 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
178 typedef _IO_off64_t (*_IO_seekpos_t
) __PMT ((_IO_FILE
*, _IO_off64_t
, int));
179 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
180 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
182 /* The 'setbuf' hook gives a buffer to the file.
183 It matches the streambuf::setbuf virtual function. */
184 typedef _IO_FILE
* (*_IO_setbuf_t
) __PMT ((_IO_FILE
*, char *, _IO_ssize_t
));
185 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
186 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
188 /* The 'sync' hook attempts to synchronize the internal data structures
189 of the file with the external state.
190 It matches the streambuf::sync virtual function. */
191 typedef int (*_IO_sync_t
) __PMT ((_IO_FILE
*));
192 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
193 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
195 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
196 It matches the streambuf::doallocate virtual function, which is not
197 in the ANSI/ISO C++ standard, but is part traditional implementations. */
198 typedef int (*_IO_doallocate_t
) __PMT ((_IO_FILE
*));
199 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
200 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
202 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
203 sysstat) are low-level hooks specific to this implementation.
204 There is no correspondence in the ANSI/ISO C++ standard library.
205 The hooks basically correspond to the Unix system functions
206 (read, write, close, lseek, and stat) except that a _IO_FILE*
207 parameter is used instead of a integer file descriptor; the default
208 implementation used for normal files just calls those functions.
209 The advantage of overriding these functions instead of the higher-level
210 ones (underflow, overflow etc) is that you can leave all the buffering
211 higher-level functions. */
213 /* The 'sysread' hook is used to read data from the external file into
214 an existing buffer. It generalizes the Unix read(2) function.
215 It matches the streambuf::sys_read virtual function, which is
216 specific to this implementation. */
217 typedef _IO_ssize_t (*_IO_read_t
) __PMT ((_IO_FILE
*, void *, _IO_ssize_t
));
218 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
219 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
221 /* The 'syswrite' hook is used to write data from an existing buffer
222 to an external file. It generalizes the Unix write(2) function.
223 It matches the streambuf::sys_write virtual function, which is
224 specific to this implementation. */
225 typedef _IO_ssize_t (*_IO_write_t
) __PMT ((_IO_FILE
*, const void *,
227 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
228 #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
230 /* The 'sysseek' hook is used to re-position an external file.
231 It generalizes the Unix lseek(2) function.
232 It matches the streambuf::sys_seek virtual function, which is
233 specific to this implementation. */
234 typedef _IO_off64_t (*_IO_seek_t
) __PMT ((_IO_FILE
*, _IO_off64_t
, int));
235 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
236 #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
238 /* The 'sysclose' hook is used to finalize (close, finish up) an
239 external file. It generalizes the Unix close(2) function.
240 It matches the streambuf::sys_close virtual function, which is
241 specific to this implementation. */
242 typedef int (*_IO_close_t
) __PMT ((_IO_FILE
*)); /* finalize */
243 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
244 #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
246 /* The 'sysstat' hook is used to get information about an external file
247 into a struct stat buffer. It generalizes the Unix fstat(2) call.
248 It matches the streambuf::sys_stat virtual function, which is
249 specific to this implementation. */
250 typedef int (*_IO_stat_t
) __PMT ((_IO_FILE
*, void *));
251 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
252 #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
254 /* The 'showmany' hook can be used to get an image how much input is
255 available. In many cases the answer will be 0 which means unknown
256 but some cases one can provide real information. */
257 typedef int (*_IO_showmanyc_t
) __PMT ((_IO_FILE
*));
258 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
259 #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
261 /* The 'imbue' hook is used to get information about the currently
262 installed locales. */
263 typedef void (*_IO_imbue_t
) __PMT ((_IO_FILE
*, void *));
264 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
265 #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
268 #define _IO_CHAR_TYPE char /* unsigned char ? */
269 #define _IO_INT_TYPE int
273 JUMP_FIELD(_G_size_t
, __dummy
);
274 #ifdef _G_USING_THUNKS
275 JUMP_FIELD(_G_size_t
, __dummy2
);
277 JUMP_FIELD(_IO_finish_t
, __finish
);
278 JUMP_FIELD(_IO_overflow_t
, __overflow
);
279 JUMP_FIELD(_IO_underflow_t
, __underflow
);
280 JUMP_FIELD(_IO_underflow_t
, __uflow
);
281 JUMP_FIELD(_IO_pbackfail_t
, __pbackfail
);
283 JUMP_FIELD(_IO_xsputn_t
, __xsputn
);
284 JUMP_FIELD(_IO_xsgetn_t
, __xsgetn
);
285 JUMP_FIELD(_IO_seekoff_t
, __seekoff
);
286 JUMP_FIELD(_IO_seekpos_t
, __seekpos
);
287 JUMP_FIELD(_IO_setbuf_t
, __setbuf
);
288 JUMP_FIELD(_IO_sync_t
, __sync
);
289 JUMP_FIELD(_IO_doallocate_t
, __doallocate
);
290 JUMP_FIELD(_IO_read_t
, __read
);
291 JUMP_FIELD(_IO_write_t
, __write
);
292 JUMP_FIELD(_IO_seek_t
, __seek
);
293 JUMP_FIELD(_IO_close_t
, __close
);
294 JUMP_FIELD(_IO_stat_t
, __stat
);
295 JUMP_FIELD(_IO_showmanyc_t
, __showmanyc
);
296 JUMP_FIELD(_IO_imbue_t
, __imbue
);
303 /* We always allocate an extra word following an _IO_FILE.
304 This contains a pointer to the function jump table used.
305 This is for compatibility with C++ streambuf; the word can
306 be used to smash to a pointer to a virtual function table. */
311 const struct _IO_jump_t
*vtable
;
314 /* Generic functions */
316 extern void _IO_switch_to_main_get_area
__P ((_IO_FILE
*));
317 extern void _IO_switch_to_backup_area
__P ((_IO_FILE
*));
318 extern int _IO_switch_to_get_mode
__P ((_IO_FILE
*));
319 extern void _IO_init
__P ((_IO_FILE
*, int));
320 extern int _IO_sputbackc
__P ((_IO_FILE
*, int));
321 extern int _IO_sungetc
__P ((_IO_FILE
*));
322 extern void _IO_un_link
__P ((_IO_FILE
*));
323 extern void _IO_link_in
__P ((_IO_FILE
*));
324 extern void _IO_doallocbuf
__P ((_IO_FILE
*));
325 extern void _IO_unsave_markers
__P ((_IO_FILE
*));
326 extern void _IO_setb
__P ((_IO_FILE
*, char *, char *, int));
327 extern unsigned _IO_adjust_column
__P ((unsigned, const char *, int));
328 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
330 extern void _IO_switch_to_main_wget_area
__P ((_IO_FILE
*));
331 extern void _IO_switch_to_wbackup_area
__P ((_IO_FILE
*));
332 extern int _IO_switch_to_wget_mode
__P ((_IO_FILE
*));
333 extern void _IO_wsetb
__P ((_IO_FILE
*, wchar_t *, wchar_t *, int));
334 extern wint_t _IO_sputbackwc
__P ((_IO_FILE
*, wint_t));
335 extern wint_t _IO_sungetwc
__P ((_IO_FILE
*));
336 extern void _IO_wdoallocbuf
__P ((_IO_FILE
*));
337 extern void _IO_unsave_wmarkers
__P ((_IO_FILE
*));
338 extern unsigned _IO_adjust_wcolumn
__P ((unsigned, const wchar_t *, int));
340 /* Marker-related function. */
342 extern void _IO_init_marker
__P ((struct _IO_marker
*, _IO_FILE
*));
343 extern void _IO_init_wmarker
__P ((struct _IO_marker
*, _IO_FILE
*));
344 extern void _IO_remove_marker
__P ((struct _IO_marker
*));
345 extern int _IO_marker_difference
__P ((struct _IO_marker
*,
346 struct _IO_marker
*));
347 extern int _IO_marker_delta
__P ((struct _IO_marker
*));
348 extern int _IO_wmarker_delta
__P ((struct _IO_marker
*));
349 extern int _IO_seekmark
__P ((_IO_FILE
*, struct _IO_marker
*, int));
350 extern int _IO_seekwmark
__P ((_IO_FILE
*, struct _IO_marker
*, int));
352 /* Default jumptable functions. */
354 extern int _IO_default_underflow
__P ((_IO_FILE
*));
355 extern int _IO_default_uflow
__P ((_IO_FILE
*));
356 extern wint_t _IO_wdefault_uflow
__P ((_IO_FILE
*));
357 extern int _IO_default_doallocate
__P ((_IO_FILE
*));
358 extern int _IO_wdefault_doallocate
__P ((_IO_FILE
*));
359 extern void _IO_default_finish
__P ((_IO_FILE
*, int));
360 extern void _IO_wdefault_finish
__P ((_IO_FILE
*, int));
361 extern int _IO_default_pbackfail
__P ((_IO_FILE
*, int));
362 extern wint_t _IO_wdefault_pbackfail
__P ((_IO_FILE
*, wint_t));
363 extern _IO_FILE
* _IO_default_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
364 extern _IO_FILE
* _IO_wdefault_setbuf
__P ((_IO_FILE
*, wchar_t *,
366 extern _IO_size_t _IO_default_xsputn
__P ((_IO_FILE
*, const void *,
368 extern _IO_size_t _IO_wdefault_xsputn
__P ((_IO_FILE
*, const void *,
370 extern _IO_size_t _IO_default_xsgetn
__P ((_IO_FILE
*, void *, _IO_size_t
));
371 extern _IO_size_t _IO_wdefault_xsgetn
__P ((_IO_FILE
*, void *, _IO_size_t
));
372 extern _IO_off64_t _IO_default_seekoff
__P ((_IO_FILE
*,
373 _IO_off64_t
, int, int));
374 extern _IO_off64_t _IO_default_seekpos
__P ((_IO_FILE
*, _IO_off64_t
, int));
375 extern _IO_ssize_t _IO_default_write
__P ((_IO_FILE
*, const void *,
377 extern _IO_ssize_t _IO_default_read
__P ((_IO_FILE
*, void *, _IO_ssize_t
));
378 extern int _IO_default_stat
__P ((_IO_FILE
*, void *));
379 extern _IO_off64_t _IO_default_seek
__P ((_IO_FILE
*, _IO_off64_t
, int));
380 extern int _IO_default_sync
__P ((_IO_FILE
*));
381 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
382 extern int _IO_default_showmanyc
__P ((_IO_FILE
*));
383 extern void _IO_default_imbue
__P ((_IO_FILE
*, void *));
385 extern struct _IO_jump_t _IO_file_jumps
;
386 extern struct _IO_jump_t _IO_wfile_jumps
;
387 extern struct _IO_jump_t _IO_old_file_jumps
;
388 extern struct _IO_jump_t _IO_streambuf_jumps
;
389 extern struct _IO_jump_t _IO_proc_jumps
;
390 extern struct _IO_jump_t _IO_old_proc_jumps
;
391 extern struct _IO_jump_t _IO_str_jumps
;
392 extern struct _IO_jump_t _IO_wstr_jumps
;
393 extern int _IO_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
394 extern int _IO_new_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
395 extern int _IO_old_do_write
__P ((_IO_FILE
*, const char *, _IO_size_t
));
396 extern int _IO_wdo_write
__P ((_IO_FILE
*, const wchar_t *, _IO_size_t
));
397 extern int _IO_flush_all
__P ((void));
398 extern int _IO_cleanup
__P ((void));
399 extern void _IO_flush_all_linebuffered
__P ((void));
400 extern int _IO_new_fgetpos
__P ((_IO_FILE
*, _IO_fpos_t
*));
401 extern int _IO_old_fgetpos
__P ((_IO_FILE
*, _IO_fpos_t
*));
402 extern int _IO_new_fsetpos
__P ((_IO_FILE
*, const _IO_fpos_t
*));
403 extern int _IO_old_fsetpos
__P ((_IO_FILE
*, const _IO_fpos_t
*));
404 extern int _IO_new_fgetpos64
__P ((_IO_FILE
*, _IO_fpos64_t
*));
405 extern int _IO_old_fgetpos64
__P ((_IO_FILE
*, _IO_fpos64_t
*));
406 extern int _IO_new_fsetpos64
__P ((_IO_FILE
*, const _IO_fpos64_t
*));
407 extern int _IO_old_fsetpos64
__P ((_IO_FILE
*, const _IO_fpos64_t
*));
410 #define _IO_do_flush(_f) \
412 ? _IO_do_write(_f, (_f)->_IO_write_base, \
413 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
414 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
415 ((_f)->_wide_data->_IO_write_ptr \
416 - (_f)->_wide_data->_IO_write_base)))
417 #define _IO_old_do_flush(_f) \
418 _IO_old_do_write(_f, (_f)->_IO_write_base, \
419 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
420 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
421 #define _IO_mask_flags(fp, f, mask) \
422 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
423 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
424 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
425 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
426 (fp)->_wide_data->_IO_read_ptr = (g), \
427 (fp)->_wide_data->_IO_read_end = (eg))
428 #define _IO_setp(__fp, __p, __ep) \
429 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
430 = __p, (__fp)->_IO_write_end = (__ep))
431 #define _IO_wsetp(__fp, __p, __ep) \
432 ((__fp)->_wide_data->_IO_write_base \
433 = (__fp)->_wide_data->_IO_write_ptr = __p, \
434 (__fp)->_wide_data->_IO_write_end = (__ep))
435 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
436 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
437 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
438 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
439 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
440 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
441 - (fp)->_wide_data->_IO_buf_base)
443 /* Jumptable functions for files. */
445 extern int _IO_file_doallocate
__P ((_IO_FILE
*));
446 extern _IO_FILE
* _IO_file_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
447 extern _IO_off64_t _IO_file_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
448 extern _IO_size_t _IO_file_xsputn
__P ((_IO_FILE
*, const void *, _IO_size_t
));
449 extern _IO_size_t _IO_file_xsgetn
__P ((_IO_FILE
*, void *, _IO_size_t
));
450 extern int _IO_file_stat
__P ((_IO_FILE
*, void *));
451 extern int _IO_file_close
__P ((_IO_FILE
*));
452 extern int _IO_file_underflow
__P ((_IO_FILE
*));
453 extern int _IO_file_overflow
__P ((_IO_FILE
*, int));
454 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
455 extern void _IO_file_init
__P ((_IO_FILE
*));
456 extern _IO_FILE
* _IO_file_attach
__P ((_IO_FILE
*, int));
457 extern _IO_FILE
* _IO_file_open
__P ((_IO_FILE
*, const char *, int, int,
459 extern _IO_FILE
* _IO_file_fopen
__P ((_IO_FILE
*, const char *, const char *,
461 extern _IO_ssize_t _IO_file_write
__P ((_IO_FILE
*, const void *,
463 extern _IO_ssize_t _IO_file_read
__P ((_IO_FILE
*, void *, _IO_ssize_t
));
464 extern int _IO_file_sync
__P ((_IO_FILE
*));
465 extern int _IO_file_close_it
__P ((_IO_FILE
*));
466 extern _IO_off64_t _IO_file_seek
__P ((_IO_FILE
*, _IO_off64_t
, int));
467 extern void _IO_file_finish
__P ((_IO_FILE
*, int));
469 extern _IO_FILE
* _IO_new_file_attach
__P ((_IO_FILE
*, int));
470 extern int _IO_new_file_close_it
__P ((_IO_FILE
*));
471 extern void _IO_new_file_finish
__P ((_IO_FILE
*, int));
472 extern _IO_FILE
* _IO_new_file_fopen
__P ((_IO_FILE
*, const char *, const char *,
474 extern void _IO_no_init
__P ((_IO_FILE
*, int, int, struct _IO_wide_data
*,
475 struct _IO_jump_t
*));
476 extern void _IO_new_file_init
__P ((_IO_FILE
*));
477 extern _IO_FILE
* _IO_new_file_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
478 extern int _IO_new_file_sync
__P ((_IO_FILE
*));
479 extern int _IO_new_file_underflow
__P ((_IO_FILE
*));
480 extern int _IO_new_file_overflow
__P ((_IO_FILE
*, int));
481 extern _IO_off64_t _IO_new_file_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
482 extern _IO_ssize_t _IO_new_file_write
__P ((_IO_FILE
*, const void *,
484 extern _IO_size_t _IO_new_file_xsputn
__P ((_IO_FILE
*, const void *, _IO_size_t
));
486 extern _IO_FILE
* _IO_old_file_setbuf
__P ((_IO_FILE
*, char *, _IO_ssize_t
));
487 extern _IO_off64_t _IO_old_file_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int,
489 extern _IO_size_t _IO_old_file_xsputn
__P ((_IO_FILE
*, const void *,
491 extern int _IO_old_file_underflow
__P ((_IO_FILE
*));
492 extern int _IO_old_file_overflow
__P ((_IO_FILE
*, int));
493 extern void _IO_old_file_init
__P ((_IO_FILE
*));
494 extern _IO_FILE
* _IO_old_file_attach
__P ((_IO_FILE
*, int));
495 extern _IO_FILE
* _IO_old_file_fopen
__P ((_IO_FILE
*, const char *,
497 extern _IO_ssize_t _IO_old_file_write
__P ((_IO_FILE
*, const void *,
499 extern int _IO_old_file_sync
__P ((_IO_FILE
*));
500 extern int _IO_old_file_close_it
__P ((_IO_FILE
*));
501 extern void _IO_old_file_finish
__P ((_IO_FILE
*, int));
503 extern int _IO_wfile_doallocate
__P ((_IO_FILE
*));
504 extern _IO_size_t _IO_wfile_xsputn
__P ((_IO_FILE
*, const void *,
506 extern _IO_FILE
* _IO_wfile_setbuf
__P ((_IO_FILE
*, wchar_t *, _IO_ssize_t
));
507 extern wint_t _IO_wfile_sync
__P ((_IO_FILE
*));
508 extern wint_t _IO_wfile_underflow
__P ((_IO_FILE
*));
509 extern wint_t _IO_wfile_overflow
__P ((_IO_FILE
*, wint_t));
510 extern _IO_off64_t _IO_wfile_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
512 /* Jumptable functions for proc_files. */
513 extern _IO_FILE
* _IO_proc_open
__P ((_IO_FILE
*, const char *, const char *));
514 extern _IO_FILE
* _IO_new_proc_open
__P ((_IO_FILE
*, const char *, const char *));
515 extern _IO_FILE
* _IO_old_proc_open
__P ((_IO_FILE
*, const char *, const char *));
516 extern int _IO_proc_close
__P ((_IO_FILE
*));
517 extern int _IO_new_proc_close
__P ((_IO_FILE
*));
518 extern int _IO_old_proc_close
__P ((_IO_FILE
*));
520 /* Jumptable functions for strfiles. */
521 extern int _IO_str_underflow
__P ((_IO_FILE
*));
522 extern int _IO_str_overflow
__P ((_IO_FILE
*, int));
523 extern int _IO_str_pbackfail
__P ((_IO_FILE
*, int));
524 extern _IO_off64_t _IO_str_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
525 extern void _IO_str_finish
__P ((_IO_FILE
*, int));
527 /* Other strfile functions */
528 extern void _IO_str_init_static
__P ((_IO_FILE
*, char *, int, char *));
529 extern void _IO_str_init_readonly
__P ((_IO_FILE
*, const char *, int));
530 extern _IO_ssize_t _IO_str_count
__P ((_IO_FILE
*));
532 /* And the wide character versions. */
533 extern void _IO_wstr_init_static
__P ((_IO_FILE
*, wchar_t *, int, wchar_t *));
534 extern void _IO_wstr_init_readonly
__P ((_IO_FILE
*, const char *, int));
535 extern _IO_ssize_t _IO_wstr_count
__P ((_IO_FILE
*));
536 extern _IO_wint_t _IO_wstr_overflow
__P ((_IO_FILE
*, _IO_wint_t
));
537 extern _IO_wint_t _IO_wstr_underflow
__P ((_IO_FILE
*));
538 extern _IO_off64_t _IO_wstr_seekoff
__P ((_IO_FILE
*, _IO_off64_t
, int, int));
539 extern _IO_wint_t _IO_wstr_pbackfail
__P ((_IO_FILE
*, _IO_wint_t
));
540 extern void _IO_wstr_finish
__P ((_IO_FILE
*, int));
542 extern int _IO_vasprintf
__P ((char **result_ptr
, __const
char *format
,
544 extern int _IO_vdprintf
__P ((int d
, __const
char *format
, _IO_va_list arg
));
545 extern int _IO_vsnprintf
__P ((char *string
, _IO_size_t maxlen
,
546 __const
char *format
, _IO_va_list args
));
549 extern _IO_size_t _IO_getline
__P ((_IO_FILE
*,char *, _IO_size_t
, int, int));
550 extern _IO_size_t _IO_getline_info
__P ((_IO_FILE
*,char *, _IO_size_t
,
552 extern _IO_ssize_t _IO_getdelim
__P ((char **, _IO_size_t
*, int, _IO_FILE
*));
553 extern _IO_size_t _IO_getwline
__P ((_IO_FILE
*,wchar_t *, _IO_size_t
, wint_t,
555 extern _IO_size_t _IO_getwline_info
__P ((_IO_FILE
*,wchar_t *, _IO_size_t
,
556 wint_t, int, wint_t *));
557 extern double _IO_strtod
__P ((const char *, char **));
558 extern char *_IO_dtoa
__P ((double __d
, int __mode
, int __ndigits
,
559 int *__decpt
, int *__sign
, char **__rve
));
560 extern int _IO_outfloat
__P ((double __value
, _IO_FILE
*__sb
, int __type
,
561 int __width
, int __precision
, int __flags
,
562 int __sign_mode
, int __fill
));
564 extern _IO_FILE
*_IO_list_all
;
565 extern void (*_IO_cleanup_registration_needed
) __PMT ((void));
571 # if defined __GNUG__ && \
572 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
573 # define NULL (__null)
575 # if !defined(__cplusplus)
576 # define NULL ((void*)0)
587 # include <sys/mman.h>
588 # include <sys/param.h>
590 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
591 # define MAP_ANONYMOUS MAP_ANON
594 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
596 # define _G_HAVE_MMAP 0
599 #endif /* _G_HAVE_MMAP */
604 /* When using this code in the GNU libc we must not pollute the name space. */
606 # define munmap __munmap
607 # define ftruncate __ftruncate
610 # define ROUND_TO_PAGE(_S) \
611 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
613 # define FREE_BUF(_B, _S) \
614 munmap ((_B), ROUND_TO_PAGE (_S))
615 # define ALLOC_BUF(_B, _S, _R) \
617 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
618 PROT_READ | PROT_WRITE, \
619 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
620 if ((_B) == (char *) MAP_FAILED) \
623 # define ALLOC_WBUF(_B, _S, _R) \
625 (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
626 PROT_READ | PROT_WRITE, \
627 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
628 if ((_B) == (wchar_t *) MAP_FAILED) \
632 #else /* _G_HAVE_MMAP */
634 # define FREE_BUF(_B, _S) \
636 # define ALLOC_BUF(_B, _S, _R) \
638 (_B) = (char*)malloc(_S); \
643 #endif /* _G_HAVE_MMAP */
646 # define OS_FSTAT fstat
649 extern _IO_ssize_t _IO_read
__P ((int, void *, _IO_size_t
));
650 extern _IO_ssize_t _IO_write
__P ((int, const void *, _IO_size_t
));
651 extern _IO_off64_t _IO_lseek
__P ((int, _IO_off64_t
, int));
652 extern int _IO_close
__P ((int));
653 extern int _IO_fstat
__P ((int, struct stat
*));
654 extern int _IO_vscanf
__P ((const char *, _IO_va_list
));
656 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
658 # define _IO_pos_BAD ((_IO_off64_t) -1)
660 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
661 #ifndef _IO_pos_adjust
662 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
664 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
666 # define _IO_pos_0 ((_IO_off64_t) 0)
674 /* check following! */
675 # ifdef _IO_USE_OLD_IO_FILE
676 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
677 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
678 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
679 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
681 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
682 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
683 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
684 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
688 # ifdef _IO_USE_OLD_IO_FILE
689 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
690 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
691 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, 0, _IO_pos_BAD }
693 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
694 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
695 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
696 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
701 /* VTABLE_LABEL defines NAME as of the CLASS class.
702 CNLENGTH is strlen(#CLASS). */
704 # if _G_VTABLE_LABEL_HAS_LENGTH
705 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
706 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CNLENGTH #CLASS);
708 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
709 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CLASS);
711 #endif /* __GNUC__ */
713 #if !defined(builtinbuf_vtable) && defined(__cplusplus)
715 VTABLE_LABEL(builtinbuf_vtable
, builtinbuf
, 10)
717 # if _G_VTABLE_LABEL_HAS_LENGTH
718 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
720 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
723 #endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
725 #if defined(__STDC__) || defined(__cplusplus)
726 # define _IO_va_start(args, last) va_start(args, last)
728 # define _IO_va_start(args, last) va_start(args)
731 extern struct _IO_fake_stdiobuf _IO_stdin_buf
, _IO_stdout_buf
, _IO_stderr_buf
;
734 # define COERCE_FILE(FILE) /* Nothing */
736 /* This is part of the kludge for binary compatibility with old stdio. */
737 # define COERCE_FILE(FILE) \
738 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
739 && (FILE) = *(FILE**)&((int*)fp)[1])
743 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
745 # define MAYBE_SET_EINVAL /* nothing */
749 # define CHECK_FILE(FILE, RET) \
750 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
751 else { COERCE_FILE(FILE); \
752 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
753 { MAYBE_SET_EINVAL; return RET; }}
755 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)