Update.
[glibc.git] / libio / libioP.h
blob090f98a02d54733929de151f223f69de7d0259be
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,
17 MA 02111-1307, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does
21 not cause the resulting executable to be covered by the GNU General
22 Public License. This exception does not however invalidate any
23 other reasons why the executable file might be covered by the GNU
24 General Public License. */
26 #include <errno.h>
27 #ifndef __set_errno
28 # define __set_errno(Val) errno = (Val)
29 #endif
30 #if defined __GLIBC__ && __GLIBC__ >= 2
31 # include <bits/libc-lock.h>
32 #else
33 /*# include <comthread.h>*/
34 #endif
36 #include "iolibio.h"
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
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
70 #endif
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
74 #define _IO_CHECK_WIDE(THIS) (((struct _IO_FILE *) (THIS))->_wide_data != NULL)
76 #if _IO_JUMPS_OFFSET
77 # define _IO_JUMPS_FUNC(THIS) \
78 (*(struct _IO_jump_t **) ((void *) &((struct _IO_FILE_plus *) (THIS))->vtable\
79 + (THIS)->_vtable_offset))
80 #else
81 # define _IO_JUMPS_FUNC(THIS) _IO_JUMPS(THIS)
82 #endif
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)
97 #else
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)
111 #endif
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,
153 _IO_size_t N));
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,
161 _IO_size_t N));
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,
171 int DIR, int MODE));
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 *,
228 _IO_ssize_t));
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
273 struct _IO_jump_t
275 JUMP_FIELD(_G_size_t, __dummy);
276 #ifdef _G_USING_THUNKS
277 JUMP_FIELD(_G_size_t, __dummy2);
278 #endif
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);
284 /* showmany */
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);
299 #if 0
300 get_column;
301 set_column;
302 #endif
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. */
310 struct _IO_FILE_plus
312 _IO_FILE file;
313 const struct _IO_jump_t *vtable;
316 /* Iterator type for walking global linked list of _IO_FILE objects. */
318 typedef _IO_FILE *_IO_ITER;
320 /* Generic functions */
322 extern void _IO_switch_to_main_get_area __P ((_IO_FILE *));
323 extern void _IO_switch_to_backup_area __P ((_IO_FILE *));
324 extern int _IO_switch_to_get_mode __P ((_IO_FILE *));
325 extern void _IO_init __P ((_IO_FILE *, int));
326 extern int _IO_sputbackc __P ((_IO_FILE *, int));
327 extern int _IO_sungetc __P ((_IO_FILE *));
328 extern void _IO_un_link __P ((_IO_FILE *));
329 extern void _IO_link_in __P ((_IO_FILE *));
330 extern void _IO_doallocbuf __P ((_IO_FILE *));
331 extern void _IO_unsave_markers __P ((_IO_FILE *));
332 extern void _IO_setb __P ((_IO_FILE *, char *, char *, int));
333 extern unsigned _IO_adjust_column __P ((unsigned, const char *, int));
334 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
336 extern void _IO_switch_to_main_wget_area __P ((_IO_FILE *));
337 extern void _IO_switch_to_wbackup_area __P ((_IO_FILE *));
338 extern int _IO_switch_to_wget_mode __P ((_IO_FILE *));
339 extern void _IO_wsetb __P ((_IO_FILE *, wchar_t *, wchar_t *, int));
340 extern wint_t _IO_sputbackwc __P ((_IO_FILE *, wint_t));
341 extern wint_t _IO_sungetwc __P ((_IO_FILE *));
342 extern void _IO_wdoallocbuf __P ((_IO_FILE *));
343 extern void _IO_unsave_wmarkers __P ((_IO_FILE *));
344 extern unsigned _IO_adjust_wcolumn __P ((unsigned, const wchar_t *, int));
346 /* Marker-related function. */
348 extern void _IO_init_marker __P ((struct _IO_marker *, _IO_FILE *));
349 extern void _IO_init_wmarker __P ((struct _IO_marker *, _IO_FILE *));
350 extern void _IO_remove_marker __P ((struct _IO_marker *));
351 extern int _IO_marker_difference __P ((struct _IO_marker *,
352 struct _IO_marker *));
353 extern int _IO_marker_delta __P ((struct _IO_marker *));
354 extern int _IO_wmarker_delta __P ((struct _IO_marker *));
355 extern int _IO_seekmark __P ((_IO_FILE *, struct _IO_marker *, int));
356 extern int _IO_seekwmark __P ((_IO_FILE *, struct _IO_marker *, int));
358 /* Functions for iterating global list and dealing with
359 its lock */
361 extern _IO_ITER _IO_iter_begin __P ((void));
362 extern _IO_ITER _IO_iter_end __P ((void));
363 extern _IO_ITER _IO_iter_next __P ((_IO_ITER));
364 extern _IO_FILE *_IO_iter_file __P ((_IO_ITER));
365 extern void _IO_list_lock __P ((void));
366 extern void _IO_list_unlock __P ((void));
367 extern void _IO_list_resetlock __P ((void));
369 /* Default jumptable functions. */
371 extern int _IO_default_underflow __P ((_IO_FILE *));
372 extern int _IO_default_uflow __P ((_IO_FILE *));
373 extern wint_t _IO_wdefault_uflow __P ((_IO_FILE *));
374 extern int _IO_default_doallocate __P ((_IO_FILE *));
375 extern int _IO_wdefault_doallocate __P ((_IO_FILE *));
376 extern void _IO_default_finish __P ((_IO_FILE *, int));
377 extern void _IO_wdefault_finish __P ((_IO_FILE *, int));
378 extern int _IO_default_pbackfail __P ((_IO_FILE *, int));
379 extern wint_t _IO_wdefault_pbackfail __P ((_IO_FILE *, wint_t));
380 extern _IO_FILE* _IO_default_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
381 extern _IO_FILE* _IO_wdefault_setbuf __P ((_IO_FILE *, wchar_t *,
382 _IO_ssize_t));
383 extern _IO_size_t _IO_default_xsputn __P ((_IO_FILE *, const void *,
384 _IO_size_t));
385 extern _IO_size_t _IO_wdefault_xsputn __P ((_IO_FILE *, const void *,
386 _IO_size_t));
387 extern _IO_size_t _IO_default_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
388 extern _IO_size_t _IO_wdefault_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
389 extern _IO_off64_t _IO_default_seekoff __P ((_IO_FILE *,
390 _IO_off64_t, int, int));
391 extern _IO_off64_t _IO_default_seekpos __P ((_IO_FILE *, _IO_off64_t, int));
392 extern _IO_ssize_t _IO_default_write __P ((_IO_FILE *, const void *,
393 _IO_ssize_t));
394 extern _IO_ssize_t _IO_default_read __P ((_IO_FILE *, void *, _IO_ssize_t));
395 extern int _IO_default_stat __P ((_IO_FILE *, void *));
396 extern _IO_off64_t _IO_default_seek __P ((_IO_FILE *, _IO_off64_t, int));
397 extern int _IO_default_sync __P ((_IO_FILE *));
398 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
399 extern int _IO_default_showmanyc __P ((_IO_FILE *));
400 extern void _IO_default_imbue __P ((_IO_FILE *, void *));
402 extern struct _IO_jump_t _IO_file_jumps;
403 extern struct _IO_jump_t _IO_wfile_jumps;
404 extern struct _IO_jump_t _IO_old_file_jumps;
405 extern struct _IO_jump_t _IO_streambuf_jumps;
406 extern struct _IO_jump_t _IO_proc_jumps;
407 extern struct _IO_jump_t _IO_old_proc_jumps;
408 extern struct _IO_jump_t _IO_str_jumps;
409 extern struct _IO_jump_t _IO_wstr_jumps;
410 extern struct _IO_codecvt __libio_codecvt;
411 extern int _IO_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
412 extern int _IO_new_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
413 extern int _IO_old_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
414 extern int _IO_wdo_write __P ((_IO_FILE *, const wchar_t *, _IO_size_t));
415 extern int _IO_flush_all __P ((void));
416 extern int _IO_cleanup __P ((void));
417 extern void _IO_flush_all_linebuffered __P ((void));
418 extern int _IO_new_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
419 extern int _IO_old_fgetpos __P ((_IO_FILE *, _IO_fpos_t *));
420 extern int _IO_new_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
421 extern int _IO_old_fsetpos __P ((_IO_FILE *, const _IO_fpos_t *));
422 extern int _IO_new_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
423 extern int _IO_old_fgetpos64 __P ((_IO_FILE *, _IO_fpos64_t *));
424 extern int _IO_new_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
425 extern int _IO_old_fsetpos64 __P ((_IO_FILE *, const _IO_fpos64_t *));
428 #define _IO_do_flush(_f) \
429 ((_f)->_mode <= 0 \
430 ? _IO_do_write(_f, (_f)->_IO_write_base, \
431 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
432 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
433 ((_f)->_wide_data->_IO_write_ptr \
434 - (_f)->_wide_data->_IO_write_base)))
435 #define _IO_old_do_flush(_f) \
436 _IO_old_do_write(_f, (_f)->_IO_write_base, \
437 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
438 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
439 #define _IO_mask_flags(fp, f, mask) \
440 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
441 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
442 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
443 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
444 (fp)->_wide_data->_IO_read_ptr = (g), \
445 (fp)->_wide_data->_IO_read_end = (eg))
446 #define _IO_setp(__fp, __p, __ep) \
447 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
448 = __p, (__fp)->_IO_write_end = (__ep))
449 #define _IO_wsetp(__fp, __p, __ep) \
450 ((__fp)->_wide_data->_IO_write_base \
451 = (__fp)->_wide_data->_IO_write_ptr = __p, \
452 (__fp)->_wide_data->_IO_write_end = (__ep))
453 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
454 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
455 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
456 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
457 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
458 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
459 - (fp)->_wide_data->_IO_buf_base)
461 /* Jumptable functions for files. */
463 extern int _IO_file_doallocate __P ((_IO_FILE *));
464 extern _IO_FILE* _IO_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
465 extern _IO_off64_t _IO_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
466 extern _IO_size_t _IO_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
467 extern _IO_size_t _IO_file_xsgetn __P ((_IO_FILE *, void *, _IO_size_t));
468 extern int _IO_file_stat __P ((_IO_FILE *, void *));
469 extern int _IO_file_close __P ((_IO_FILE *));
470 extern int _IO_file_underflow __P ((_IO_FILE *));
471 extern int _IO_file_overflow __P ((_IO_FILE *, int));
472 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
473 extern void _IO_file_init __P ((_IO_FILE *));
474 extern _IO_FILE* _IO_file_attach __P ((_IO_FILE *, int));
475 extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int,
476 int, int));
477 extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *,
478 int));
479 extern _IO_ssize_t _IO_file_write __P ((_IO_FILE *, const void *,
480 _IO_ssize_t));
481 extern _IO_ssize_t _IO_file_read __P ((_IO_FILE *, void *, _IO_ssize_t));
482 extern int _IO_file_sync __P ((_IO_FILE *));
483 extern int _IO_file_close_it __P ((_IO_FILE *));
484 extern _IO_off64_t _IO_file_seek __P ((_IO_FILE *, _IO_off64_t, int));
485 extern void _IO_file_finish __P ((_IO_FILE *, int));
487 extern _IO_FILE* _IO_new_file_attach __P ((_IO_FILE *, int));
488 extern int _IO_new_file_close_it __P ((_IO_FILE *));
489 extern void _IO_new_file_finish __P ((_IO_FILE *, int));
490 extern _IO_FILE* _IO_new_file_fopen __P ((_IO_FILE *, const char *, const char *,
491 int));
492 extern void _IO_no_init __P ((_IO_FILE *, int, int, struct _IO_wide_data *,
493 struct _IO_jump_t *));
494 extern void _IO_new_file_init __P ((_IO_FILE *));
495 extern _IO_FILE* _IO_new_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
496 extern int _IO_new_file_sync __P ((_IO_FILE *));
497 extern int _IO_new_file_underflow __P ((_IO_FILE *));
498 extern int _IO_new_file_overflow __P ((_IO_FILE *, int));
499 extern _IO_off64_t _IO_new_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
500 extern _IO_ssize_t _IO_new_file_write __P ((_IO_FILE *, const void *,
501 _IO_ssize_t));
502 extern _IO_size_t _IO_new_file_xsputn __P ((_IO_FILE *, const void *, _IO_size_t));
504 extern _IO_FILE* _IO_old_file_setbuf __P ((_IO_FILE *, char *, _IO_ssize_t));
505 extern _IO_off64_t _IO_old_file_seekoff __P ((_IO_FILE *, _IO_off64_t, int,
506 int));
507 extern _IO_size_t _IO_old_file_xsputn __P ((_IO_FILE *, const void *,
508 _IO_size_t));
509 extern int _IO_old_file_underflow __P ((_IO_FILE *));
510 extern int _IO_old_file_overflow __P ((_IO_FILE *, int));
511 extern void _IO_old_file_init __P ((_IO_FILE *));
512 extern _IO_FILE* _IO_old_file_attach __P ((_IO_FILE *, int));
513 extern _IO_FILE* _IO_old_file_fopen __P ((_IO_FILE *, const char *,
514 const char *));
515 extern _IO_ssize_t _IO_old_file_write __P ((_IO_FILE *, const void *,
516 _IO_ssize_t));
517 extern int _IO_old_file_sync __P ((_IO_FILE *));
518 extern int _IO_old_file_close_it __P ((_IO_FILE *));
519 extern void _IO_old_file_finish __P ((_IO_FILE *, int));
521 extern int _IO_wfile_doallocate __P ((_IO_FILE *));
522 extern _IO_size_t _IO_wfile_xsputn __P ((_IO_FILE *, const void *,
523 _IO_size_t));
524 extern _IO_FILE* _IO_wfile_setbuf __P ((_IO_FILE *, wchar_t *, _IO_ssize_t));
525 extern wint_t _IO_wfile_sync __P ((_IO_FILE *));
526 extern wint_t _IO_wfile_underflow __P ((_IO_FILE *));
527 extern wint_t _IO_wfile_overflow __P ((_IO_FILE *, wint_t));
528 extern _IO_off64_t _IO_wfile_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
530 /* Jumptable functions for proc_files. */
531 extern _IO_FILE* _IO_proc_open __P ((_IO_FILE *, const char *, const char *));
532 extern _IO_FILE* _IO_new_proc_open __P ((_IO_FILE *, const char *, const char *));
533 extern _IO_FILE* _IO_old_proc_open __P ((_IO_FILE *, const char *, const char *));
534 extern int _IO_proc_close __P ((_IO_FILE *));
535 extern int _IO_new_proc_close __P ((_IO_FILE *));
536 extern int _IO_old_proc_close __P ((_IO_FILE *));
538 /* Jumptable functions for strfiles. */
539 extern int _IO_str_underflow __P ((_IO_FILE *));
540 extern int _IO_str_overflow __P ((_IO_FILE *, int));
541 extern int _IO_str_pbackfail __P ((_IO_FILE *, int));
542 extern _IO_off64_t _IO_str_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
543 extern void _IO_str_finish __P ((_IO_FILE *, int));
545 /* Other strfile functions */
546 extern void _IO_str_init_static __P ((_IO_FILE *, char *, int, char *));
547 extern void _IO_str_init_readonly __P ((_IO_FILE *, const char *, int));
548 extern _IO_ssize_t _IO_str_count __P ((_IO_FILE *));
550 /* And the wide character versions. */
551 extern void _IO_wstr_init_static __P ((_IO_FILE *, wchar_t *, int, wchar_t *));
552 extern void _IO_wstr_init_readonly __P ((_IO_FILE *, const char *, int));
553 extern _IO_ssize_t _IO_wstr_count __P ((_IO_FILE *));
554 extern _IO_wint_t _IO_wstr_overflow __P ((_IO_FILE *, _IO_wint_t));
555 extern _IO_wint_t _IO_wstr_underflow __P ((_IO_FILE *));
556 extern _IO_off64_t _IO_wstr_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
557 extern _IO_wint_t _IO_wstr_pbackfail __P ((_IO_FILE *, _IO_wint_t));
558 extern void _IO_wstr_finish __P ((_IO_FILE *, int));
560 extern int _IO_vasprintf __P ((char **result_ptr, __const char *format,
561 _IO_va_list args));
562 extern int _IO_vdprintf __P ((int d, __const char *format, _IO_va_list arg));
563 extern int _IO_vsnprintf __P ((char *string, _IO_size_t maxlen,
564 __const char *format, _IO_va_list args));
567 extern _IO_size_t _IO_getline __P ((_IO_FILE *,char *, _IO_size_t, int, int));
568 extern _IO_size_t _IO_getline_info __P ((_IO_FILE *,char *, _IO_size_t,
569 int, int, int *));
570 extern _IO_ssize_t _IO_getdelim __P ((char **, _IO_size_t *, int, _IO_FILE *));
571 extern _IO_size_t _IO_getwline __P ((_IO_FILE *,wchar_t *, _IO_size_t, wint_t,
572 int));
573 extern _IO_size_t _IO_getwline_info __P ((_IO_FILE *,wchar_t *, _IO_size_t,
574 wint_t, int, wint_t *));
575 extern double _IO_strtod __P ((const char *, char **));
576 extern char *_IO_dtoa __P ((double __d, int __mode, int __ndigits,
577 int *__decpt, int *__sign, char **__rve));
578 extern int _IO_outfloat __P ((double __value, _IO_FILE *__sb, int __type,
579 int __width, int __precision, int __flags,
580 int __sign_mode, int __fill));
582 extern _IO_FILE *_IO_list_all;
583 extern void (*_IO_cleanup_registration_needed) __PMT ((void));
585 #ifndef EOF
586 # define EOF (-1)
587 #endif
588 #ifndef NULL
589 # if defined __GNUG__ && \
590 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
591 # define NULL (__null)
592 # else
593 # if !defined(__cplusplus)
594 # define NULL ((void*)0)
595 # else
596 # define NULL (0)
597 # endif
598 # endif
599 #endif
601 #if _G_HAVE_MMAP
603 # include <unistd.h>
604 # include <fcntl.h>
605 # include <sys/mman.h>
606 # include <sys/param.h>
608 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
609 # define MAP_ANONYMOUS MAP_ANON
610 # endif
612 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
613 # undef _G_HAVE_MMAP
614 # define _G_HAVE_MMAP 0
615 # endif
617 #endif /* _G_HAVE_MMAP */
619 #if _G_HAVE_MMAP
621 # ifdef _LIBC
622 /* When using this code in the GNU libc we must not pollute the name space. */
623 # define mmap __mmap
624 # define munmap __munmap
625 # define ftruncate __ftruncate
626 # endif
628 # define ROUND_TO_PAGE(_S) \
629 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
631 # define FREE_BUF(_B, _S) \
632 munmap ((_B), ROUND_TO_PAGE (_S))
633 # define ALLOC_BUF(_B, _S, _R) \
634 do { \
635 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
636 PROT_READ | PROT_WRITE, \
637 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
638 if ((_B) == (char *) MAP_FAILED) \
639 return (_R); \
640 } while (0)
641 # define ALLOC_WBUF(_B, _S, _R) \
642 do { \
643 (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
644 PROT_READ | PROT_WRITE, \
645 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
646 if ((_B) == (wchar_t *) MAP_FAILED) \
647 return (_R); \
648 } while (0)
650 #else /* _G_HAVE_MMAP */
652 # define FREE_BUF(_B, _S) \
653 free(_B)
654 # define ALLOC_BUF(_B, _S, _R) \
655 do { \
656 (_B) = (char*)malloc(_S); \
657 if ((_B) == NULL) \
658 return (_R); \
659 } while (0)
660 # define ALLOC_WBUF(_B, _S, _R) \
661 do { \
662 (_B) = (wchar_t *)malloc(_S); \
663 if ((_B) == NULL) \
664 return (_R); \
665 } while (0)
667 #endif /* _G_HAVE_MMAP */
669 #ifndef OS_FSTAT
670 # define OS_FSTAT fstat
671 #endif
672 struct stat;
673 extern _IO_ssize_t _IO_read __P ((int, void *, _IO_size_t));
674 extern _IO_ssize_t _IO_write __P ((int, const void *, _IO_size_t));
675 extern _IO_off64_t _IO_lseek __P ((int, _IO_off64_t, int));
676 extern int _IO_close __P ((int));
677 extern int _IO_fstat __P ((int, struct stat *));
678 extern int _IO_vscanf __P ((const char *, _IO_va_list));
680 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
681 #ifndef _IO_pos_BAD
682 # define _IO_pos_BAD ((_IO_off64_t) -1)
683 #endif
684 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
685 #ifndef _IO_pos_adjust
686 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
687 #endif
688 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
689 #ifndef _IO_pos_0
690 # define _IO_pos_0 ((_IO_off64_t) 0)
691 #endif
693 #ifdef __cplusplus
695 #endif
697 #ifdef _IO_MTSAFE_IO
698 /* check following! */
699 # ifdef _IO_USE_OLD_IO_FILE
700 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
701 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
702 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
703 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
704 # else
705 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
706 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
707 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
708 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
709 NULL, WDP, 0 }
710 # endif
711 #else
712 # ifdef _IO_USE_OLD_IO_FILE
713 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
714 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
715 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, 0, _IO_pos_BAD }
716 # else
717 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
718 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
719 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CHAIN, FD, \
720 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
721 NULL, WDP, 0 }
722 # endif
723 #endif
725 /* VTABLE_LABEL defines NAME as of the CLASS class.
726 CNLENGTH is strlen(#CLASS). */
727 #ifdef __GNUC__
728 # if _G_VTABLE_LABEL_HAS_LENGTH
729 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
730 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CNLENGTH #CLASS);
731 # else
732 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
733 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CLASS);
734 # endif
735 #endif /* __GNUC__ */
737 #if !defined(builtinbuf_vtable) && defined(__cplusplus)
738 # ifdef __GNUC__
739 VTABLE_LABEL(builtinbuf_vtable, builtinbuf, 10)
740 # else
741 # if _G_VTABLE_LABEL_HAS_LENGTH
742 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
743 # else
744 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
745 # endif
746 # endif
747 #endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
749 #if defined(__STDC__) || defined(__cplusplus)
750 # define _IO_va_start(args, last) va_start(args, last)
751 #else
752 # define _IO_va_start(args, last) va_start(args)
753 #endif
755 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
757 #if 1
758 # define COERCE_FILE(FILE) /* Nothing */
759 #else
760 /* This is part of the kludge for binary compatibility with old stdio. */
761 # define COERCE_FILE(FILE) \
762 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
763 && (FILE) = *(FILE**)&((int*)fp)[1])
764 #endif
766 #ifdef EINVAL
767 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
768 #else
769 # define MAYBE_SET_EINVAL /* nothing */
770 #endif
772 #ifdef IO_DEBUG
773 # define CHECK_FILE(FILE, RET) \
774 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
775 else { COERCE_FILE(FILE); \
776 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
777 { MAYBE_SET_EINVAL; return RET; }}
778 #else
779 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
780 #endif