Update.
[glibc.git] / libio / libioP.h
blob319b0fd5f3052d2cca41f1e0d895cecfa5f9578e
1 /* Copyright (C) 1993, 1997-2003, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA.
19 As a special exception, if you link the code in this file with
20 files compiled with a GNU compiler to produce an executable,
21 that does not cause the resulting executable to be covered by
22 the GNU Lesser General Public License. This exception does not
23 however invalidate any other reasons why the executable file
24 might be covered by the GNU Lesser General Public License.
25 This exception applies to code released by its copyright holders
26 in files containing the exception. */
28 #include <errno.h>
29 #ifndef __set_errno
30 # define __set_errno(Val) errno = (Val)
31 #endif
32 #if defined __GLIBC__ && __GLIBC__ >= 2
33 # include <bits/libc-lock.h>
34 #else
35 /*# include <comthread.h>*/
36 #endif
38 #include "iolibio.h"
40 /* Control of exported symbols. Used in glibc. By default we don't
41 do anything. */
42 #ifndef INTUSE
43 # define INTUSE(name) name
44 #endif
45 #ifndef INTDEF
46 # define INTDEF(name)
47 #endif
48 #ifndef INTDEF2
49 # define INTDEF2(name)
50 #endif
51 #ifndef libc_hidden_proto
52 # define libc_hidden_proto(name)
53 #endif
54 #ifndef libc_hidden_def
55 # define libc_hidden_def(name)
56 #endif
57 #ifndef libc_hidden_weak
58 # define libc_hidden_weak(name)
59 #endif
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
65 #define _IO_seek_set 0
66 #define _IO_seek_cur 1
67 #define _IO_seek_end 2
69 /* THE JUMPTABLE FUNCTIONS.
71 * The _IO_FILE type is used to implement the FILE type in GNU libc,
72 * as well as the streambuf class in GNU iostreams for C++.
73 * These are all the same, just used differently.
74 * An _IO_FILE (or FILE) object is allows followed by a pointer to
75 * a jump table (of pointers to functions). The pointer is accessed
76 * with the _IO_JUMPS macro. The jump table has a eccentric format,
77 * so as to be compatible with the layout of a C++ virtual function table.
78 * (as implemented by g++). When a pointer to a streambuf object is
79 * coerced to an (_IO_FILE*), then _IO_JUMPS on the result just
80 * happens to point to the virtual function table of the streambuf.
81 * Thus the _IO_JUMPS function table used for C stdio/libio does
82 * double duty as the virtual function table for C++ streambuf.
84 * The entries in the _IO_JUMPS function table (and hence also the
85 * virtual functions of a streambuf) are described below.
86 * The first parameter of each function entry is the _IO_FILE/streambuf
87 * object being acted on (i.e. the 'this' parameter).
90 #ifdef _LIBC
91 # include <shlib-compat.h>
92 # if !SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
93 /* Setting this macro disables the use of the _vtable_offset
94 bias in _IO_JUMPS_FUNCS, below. That is only needed if we
95 want to support old binaries (see oldfileops.c). */
96 # define _G_IO_NO_BACKWARD_COMPAT 1
97 # endif
98 #endif
100 #if (!defined _IO_USE_OLD_IO_FILE \
101 && (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0))
102 # define _IO_JUMPS_OFFSET 1
103 #endif
105 #define _IO_JUMPS(THIS) (THIS)->vtable
106 #define _IO_WIDE_JUMPS(THIS) ((struct _IO_FILE *) (THIS))->_wide_data->_wide_vtable
107 #define _IO_CHECK_WIDE(THIS) (((struct _IO_FILE *) (THIS))->_wide_data != NULL)
109 #if _IO_JUMPS_OFFSET
110 # define _IO_JUMPS_FUNC(THIS) \
111 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS ((struct _IO_FILE_plus *) (THIS)) \
112 + (THIS)->_vtable_offset))
113 # define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
114 #else
115 # define _IO_JUMPS_FUNC(THIS) _IO_JUMPS ((struct _IO_FILE_plus *) (THIS))
116 # define _IO_vtable_offset(THIS) 0
117 #endif
118 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
119 #ifdef _G_USING_THUNKS
120 # define JUMP_FIELD(TYPE, NAME) TYPE NAME
121 # define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
122 # define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
123 # define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
124 # define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
125 # define JUMP_INIT(NAME, VALUE) VALUE
126 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
128 # define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
129 # define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
130 # define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
131 # define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
132 #else
133 /* These macros will change when we re-implement vtables to use "thunks"! */
134 # define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME
135 # define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
136 # define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
137 # define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
138 # define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
139 # define JUMP_INIT(NAME, VALUE) {0, 0, VALUE}
140 # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0)
142 # define WJUMP0(FUNC, THIS) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS)
143 # define WJUMP1(FUNC, THIS, X1) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1)
144 # define WJUMP2(FUNC, THIS, X1, X2) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2)
145 # define WJUMP3(FUNC, THIS, X1,X2,X3) _IO_WIDE_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3)
146 #endif
148 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
149 It does not delete (free) it, but does everything else to finalize it.
150 It matches the streambuf::~streambuf virtual destructor. */
151 typedef void (*_IO_finish_t) (_IO_FILE *, int); /* finalize */
152 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
153 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
155 /* The 'overflow' hook flushes the buffer.
156 The second argument is a character, or EOF.
157 It matches the streambuf::overflow virtual function. */
158 typedef int (*_IO_overflow_t) (_IO_FILE *, int);
159 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
160 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
162 /* The 'underflow' hook tries to fills the get buffer.
163 It returns the next character (as an unsigned char) or EOF. The next
164 character remains in the get buffer, and the get position is not changed.
165 It matches the streambuf::underflow virtual function. */
166 typedef int (*_IO_underflow_t) (_IO_FILE *);
167 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
168 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
170 /* The 'uflow' hook returns the next character in the input stream
171 (cast to unsigned char), and increments the read position;
172 EOF is returned on failure.
173 It matches the streambuf::uflow virtual function, which is not in the
174 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
175 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
176 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
178 /* The 'pbackfail' hook handles backing up.
179 It matches the streambuf::pbackfail virtual function. */
180 typedef int (*_IO_pbackfail_t) (_IO_FILE *, int);
181 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
182 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
184 /* The 'xsputn' hook writes upto N characters from buffer DATA.
185 Returns the number of character actually written.
186 It matches the streambuf::xsputn virtual function. */
187 typedef _IO_size_t (*_IO_xsputn_t) (_IO_FILE *FP, const void *DATA,
188 _IO_size_t N);
189 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
190 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
192 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
193 Returns the number of character actually read.
194 It matches the streambuf::xsgetn virtual function. */
195 typedef _IO_size_t (*_IO_xsgetn_t) (_IO_FILE *FP, void *DATA, _IO_size_t N);
196 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
197 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
199 /* The 'seekoff' hook moves the stream position to a new position
200 relative to the start of the file (if DIR==0), the current position
201 (MODE==1), or the end of the file (MODE==2).
202 It matches the streambuf::seekoff virtual function.
203 It is also used for the ANSI fseek function. */
204 typedef _IO_off64_t (*_IO_seekoff_t) (_IO_FILE *FP, _IO_off64_t OFF, int DIR,
205 int MODE);
206 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
207 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
209 /* The 'seekpos' hook also moves the stream position,
210 but to an absolute position given by a fpos64_t (seekpos).
211 It matches the streambuf::seekpos virtual function.
212 It is also used for the ANSI fgetpos and fsetpos functions. */
213 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
214 typedef _IO_off64_t (*_IO_seekpos_t) (_IO_FILE *, _IO_off64_t, int);
215 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
216 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
218 /* The 'setbuf' hook gives a buffer to the file.
219 It matches the streambuf::setbuf virtual function. */
220 typedef _IO_FILE* (*_IO_setbuf_t) (_IO_FILE *, char *, _IO_ssize_t);
221 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
222 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
224 /* The 'sync' hook attempts to synchronize the internal data structures
225 of the file with the external state.
226 It matches the streambuf::sync virtual function. */
227 typedef int (*_IO_sync_t) (_IO_FILE *);
228 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
229 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
231 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
232 It matches the streambuf::doallocate virtual function, which is not
233 in the ANSI/ISO C++ standard, but is part traditional implementations. */
234 typedef int (*_IO_doallocate_t) (_IO_FILE *);
235 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
236 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
238 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
239 sysstat) are low-level hooks specific to this implementation.
240 There is no correspondence in the ANSI/ISO C++ standard library.
241 The hooks basically correspond to the Unix system functions
242 (read, write, close, lseek, and stat) except that a _IO_FILE*
243 parameter is used instead of a integer file descriptor; the default
244 implementation used for normal files just calls those functions.
245 The advantage of overriding these functions instead of the higher-level
246 ones (underflow, overflow etc) is that you can leave all the buffering
247 higher-level functions. */
249 /* The 'sysread' hook is used to read data from the external file into
250 an existing buffer. It generalizes the Unix read(2) function.
251 It matches the streambuf::sys_read virtual function, which is
252 specific to this implementation. */
253 typedef _IO_ssize_t (*_IO_read_t) (_IO_FILE *, void *, _IO_ssize_t);
254 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
255 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
257 /* The 'syswrite' hook is used to write data from an existing buffer
258 to an external file. It generalizes the Unix write(2) function.
259 It matches the streambuf::sys_write virtual function, which is
260 specific to this implementation. */
261 typedef _IO_ssize_t (*_IO_write_t) (_IO_FILE *, const void *, _IO_ssize_t);
262 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
263 #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
265 /* The 'sysseek' hook is used to re-position an external file.
266 It generalizes the Unix lseek(2) function.
267 It matches the streambuf::sys_seek virtual function, which is
268 specific to this implementation. */
269 typedef _IO_off64_t (*_IO_seek_t) (_IO_FILE *, _IO_off64_t, int);
270 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
271 #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
273 /* The 'sysclose' hook is used to finalize (close, finish up) an
274 external file. It generalizes the Unix close(2) function.
275 It matches the streambuf::sys_close virtual function, which is
276 specific to this implementation. */
277 typedef int (*_IO_close_t) (_IO_FILE *); /* finalize */
278 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
279 #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
281 /* The 'sysstat' hook is used to get information about an external file
282 into a struct stat buffer. It generalizes the Unix fstat(2) call.
283 It matches the streambuf::sys_stat virtual function, which is
284 specific to this implementation. */
285 typedef int (*_IO_stat_t) (_IO_FILE *, void *);
286 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
287 #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
289 /* The 'showmany' hook can be used to get an image how much input is
290 available. In many cases the answer will be 0 which means unknown
291 but some cases one can provide real information. */
292 typedef int (*_IO_showmanyc_t) (_IO_FILE *);
293 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
294 #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
296 /* The 'imbue' hook is used to get information about the currently
297 installed locales. */
298 typedef void (*_IO_imbue_t) (_IO_FILE *, void *);
299 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
300 #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
303 #define _IO_CHAR_TYPE char /* unsigned char ? */
304 #define _IO_INT_TYPE int
306 struct _IO_jump_t
308 JUMP_FIELD(_G_size_t, __dummy);
309 #ifdef _G_USING_THUNKS
310 JUMP_FIELD(_G_size_t, __dummy2);
311 #endif
312 JUMP_FIELD(_IO_finish_t, __finish);
313 JUMP_FIELD(_IO_overflow_t, __overflow);
314 JUMP_FIELD(_IO_underflow_t, __underflow);
315 JUMP_FIELD(_IO_underflow_t, __uflow);
316 JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
317 /* showmany */
318 JUMP_FIELD(_IO_xsputn_t, __xsputn);
319 JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
320 JUMP_FIELD(_IO_seekoff_t, __seekoff);
321 JUMP_FIELD(_IO_seekpos_t, __seekpos);
322 JUMP_FIELD(_IO_setbuf_t, __setbuf);
323 JUMP_FIELD(_IO_sync_t, __sync);
324 JUMP_FIELD(_IO_doallocate_t, __doallocate);
325 JUMP_FIELD(_IO_read_t, __read);
326 JUMP_FIELD(_IO_write_t, __write);
327 JUMP_FIELD(_IO_seek_t, __seek);
328 JUMP_FIELD(_IO_close_t, __close);
329 JUMP_FIELD(_IO_stat_t, __stat);
330 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
331 JUMP_FIELD(_IO_imbue_t, __imbue);
332 #if 0
333 get_column;
334 set_column;
335 #endif
338 /* We always allocate an extra word following an _IO_FILE.
339 This contains a pointer to the function jump table used.
340 This is for compatibility with C++ streambuf; the word can
341 be used to smash to a pointer to a virtual function table. */
343 struct _IO_FILE_plus
345 _IO_FILE file;
346 const struct _IO_jump_t *vtable;
349 #ifdef _IO_USE_OLD_IO_FILE
350 /* This structure is used by the compatibility code as if it were an
351 _IO_FILE_plus, but has enough space to initialize the _mode argument
352 of an _IO_FILE_complete. */
353 struct _IO_FILE_complete_plus
355 struct _IO_FILE_complete file;
356 const struct _IO_jump_t *vtable;
358 #endif
360 /* Special file type for fopencookie function. */
361 struct _IO_cookie_file
363 struct _IO_FILE_plus __fp;
364 void *__cookie;
365 _IO_cookie_io_functions_t __io_functions;
368 _IO_FILE *_IO_fopencookie (void *cookie, const char *mode,
369 _IO_cookie_io_functions_t io_functions);
372 /* Iterator type for walking global linked list of _IO_FILE objects. */
374 typedef struct _IO_FILE *_IO_ITER;
376 /* Generic functions */
378 extern void _IO_switch_to_main_get_area (_IO_FILE *) __THROW;
379 extern void _IO_switch_to_backup_area (_IO_FILE *) __THROW;
380 extern int _IO_switch_to_get_mode (_IO_FILE *) __THROW;
381 extern void _IO_init (_IO_FILE *, int) __THROW;
382 extern int _IO_sputbackc (_IO_FILE *, int) __THROW;
383 extern int _IO_sungetc (_IO_FILE *) __THROW;
384 extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
385 extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
386 extern void _IO_doallocbuf (_IO_FILE *) __THROW;
387 extern void _IO_unsave_markers (_IO_FILE *) __THROW;
388 extern void _IO_setb (_IO_FILE *, char *, char *, int) __THROW;
389 extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
390 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
392 extern void _IO_switch_to_main_wget_area (_IO_FILE *) __THROW;
393 extern void _IO_switch_to_wbackup_area (_IO_FILE *) __THROW;
394 extern int _IO_switch_to_wget_mode (_IO_FILE *) __THROW;
395 extern void _IO_wsetb (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW;
396 extern wint_t _IO_sputbackwc (_IO_FILE *, wint_t) __THROW;
397 extern wint_t _IO_sungetwc (_IO_FILE *) __THROW;
398 extern void _IO_wdoallocbuf (_IO_FILE *) __THROW;
399 extern void _IO_unsave_wmarkers (_IO_FILE *) __THROW;
400 extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
402 /* Marker-related function. */
404 extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *) __THROW;
405 extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *) __THROW;
406 extern void _IO_remove_marker (struct _IO_marker *) __THROW;
407 extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
408 __THROW;
409 extern int _IO_marker_delta (struct _IO_marker *) __THROW;
410 extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
411 extern int _IO_seekmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
412 extern int _IO_seekwmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
414 /* Functions for iterating global list and dealing with its lock */
416 extern _IO_ITER _IO_iter_begin (void) __THROW;
417 libc_hidden_proto (_IO_iter_begin)
418 extern _IO_ITER _IO_iter_end (void) __THROW;
419 libc_hidden_proto (_IO_iter_end)
420 extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
421 libc_hidden_proto (_IO_iter_next)
422 extern _IO_FILE *_IO_iter_file (_IO_ITER) __THROW;
423 libc_hidden_proto (_IO_iter_file)
424 extern void _IO_list_lock (void) __THROW;
425 libc_hidden_proto (_IO_list_lock)
426 extern void _IO_list_unlock (void) __THROW;
427 libc_hidden_proto (_IO_list_unlock)
428 extern void _IO_list_resetlock (void) __THROW;
429 libc_hidden_proto (_IO_list_resetlock)
431 /* Default jumptable functions. */
433 extern int _IO_default_underflow (_IO_FILE *) __THROW;
434 extern int _IO_default_uflow (_IO_FILE *) __THROW;
435 extern wint_t _IO_wdefault_uflow (_IO_FILE *) __THROW;
436 extern int _IO_default_doallocate (_IO_FILE *) __THROW;
437 extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW;
438 extern void _IO_default_finish (_IO_FILE *, int) __THROW;
439 extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW;
440 extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW;
441 extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW;
442 extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t) __THROW;
443 extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t);
444 extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t);
445 extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t);
446 extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t);
447 extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int)
448 __THROW;
449 extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int) __THROW;
450 extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t);
451 extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t);
452 extern int _IO_default_stat (_IO_FILE *, void *) __THROW;
453 extern _IO_off64_t _IO_default_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
454 extern int _IO_default_sync (_IO_FILE *) __THROW;
455 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
456 extern int _IO_default_showmanyc (_IO_FILE *) __THROW;
457 extern void _IO_default_imbue (_IO_FILE *, void *) __THROW;
459 extern const struct _IO_jump_t _IO_file_jumps;
460 libc_hidden_proto (_IO_file_jumps)
461 extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
462 extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
463 extern const struct _IO_jump_t _IO_wfile_jumps;
464 libc_hidden_proto (_IO_wfile_jumps)
465 extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
466 extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
467 extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
468 extern const struct _IO_jump_t _IO_streambuf_jumps;
469 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
470 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
471 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
472 extern struct _IO_codecvt __libio_codecvt attribute_hidden;
473 extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t) __THROW;
474 extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t) __THROW;
475 extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t) __THROW;
476 extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t) __THROW;
477 extern int _IO_flush_all_lockp (int) __THROW;
478 extern int _IO_flush_all (void) __THROW;
479 extern int _IO_cleanup (void) __THROW;
480 extern void _IO_flush_all_linebuffered (void) __THROW;
481 extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *) __THROW;
482 extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *) __THROW;
483 extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *) __THROW;
484 extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *) __THROW;
485 extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *) __THROW;
486 extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *) __THROW;
487 extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *) __THROW;
488 extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *) __THROW;
489 extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW;
492 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
493 # define _IO_do_flush(_f) \
494 ((_f)->_mode <= 0 \
495 ? INTUSE(_IO_do_write)(_f, (_f)->_IO_write_base, \
496 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
497 : INTUSE(_IO_wdo_write)(_f, (_f)->_wide_data->_IO_write_base, \
498 ((_f)->_wide_data->_IO_write_ptr \
499 - (_f)->_wide_data->_IO_write_base)))
500 #else
501 # define _IO_do_flush(_f) \
502 INTUSE(_IO_do_write)(_f, (_f)->_IO_write_base, \
503 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
504 #endif
505 #define _IO_old_do_flush(_f) \
506 _IO_old_do_write(_f, (_f)->_IO_write_base, \
507 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
508 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
509 #define _IO_mask_flags(fp, f, mask) \
510 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
511 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
512 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
513 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
514 (fp)->_wide_data->_IO_read_ptr = (g), \
515 (fp)->_wide_data->_IO_read_end = (eg))
516 #define _IO_setp(__fp, __p, __ep) \
517 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
518 = __p, (__fp)->_IO_write_end = (__ep))
519 #define _IO_wsetp(__fp, __p, __ep) \
520 ((__fp)->_wide_data->_IO_write_base \
521 = (__fp)->_wide_data->_IO_write_ptr = __p, \
522 (__fp)->_wide_data->_IO_write_end = (__ep))
523 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
524 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
525 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
526 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
527 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
528 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
529 - (fp)->_wide_data->_IO_buf_base)
531 /* Jumptable functions for files. */
533 extern int _IO_file_doallocate (_IO_FILE *) __THROW;
534 extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t) __THROW;
535 extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int)
536 __THROW;
537 extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int)
538 __THROW;
539 extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t)
540 __THROW;
541 extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t) __THROW;
542 extern int _IO_file_stat (_IO_FILE *, void *) __THROW;
543 extern int _IO_file_close (_IO_FILE *) __THROW;
544 extern int _IO_file_close_mmap (_IO_FILE *) __THROW;
545 extern int _IO_file_underflow (_IO_FILE *) __THROW;
546 extern int _IO_file_underflow_mmap (_IO_FILE *) __THROW;
547 extern int _IO_file_underflow_maybe_mmap (_IO_FILE *) __THROW;
548 extern int _IO_file_overflow (_IO_FILE *, int) __THROW;
549 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
550 extern void _IO_file_init (struct _IO_FILE_plus *) __THROW;
551 extern _IO_FILE* _IO_file_attach (_IO_FILE *, int) __THROW;
552 extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int)
553 __THROW;
554 libc_hidden_proto (_IO_file_open)
555 extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int)
556 __THROW;
557 extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t)
558 __THROW;
559 extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t) __THROW;
560 extern int _IO_file_sync (_IO_FILE *) __THROW;
561 extern int _IO_file_close_it (_IO_FILE *) __THROW;
562 extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
563 extern void _IO_file_finish (_IO_FILE *, int) __THROW;
565 extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int) __THROW;
566 extern int _IO_new_file_close_it (_IO_FILE *) __THROW;
567 extern void _IO_new_file_finish (_IO_FILE *, int) __THROW;
568 extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *,
569 int) __THROW;
570 extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *,
571 const struct _IO_jump_t *) __THROW;
572 extern void _IO_new_file_init (struct _IO_FILE_plus *) __THROW;
573 extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t) __THROW;
574 extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t)
575 __THROW;
576 extern int _IO_new_file_sync (_IO_FILE *) __THROW;
577 extern int _IO_new_file_underflow (_IO_FILE *) __THROW;
578 extern int _IO_new_file_overflow (_IO_FILE *, int) __THROW;
579 extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int)
580 __THROW;
581 extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t)
582 __THROW;
583 extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t)
584 __THROW;
586 extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t) __THROW;
587 extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int)
588 __THROW;
589 extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t)
590 __THROW;
591 extern int _IO_old_file_underflow (_IO_FILE *) __THROW;
592 extern int _IO_old_file_overflow (_IO_FILE *, int) __THROW;
593 extern void _IO_old_file_init (struct _IO_FILE_plus *) __THROW;
594 extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int) __THROW;
595 extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *)
596 __THROW;
597 extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t)
598 __THROW;
599 extern int _IO_old_file_sync (_IO_FILE *) __THROW;
600 extern int _IO_old_file_close_it (_IO_FILE *) __THROW;
601 extern void _IO_old_file_finish (_IO_FILE *, int) __THROW;
603 extern int _IO_wfile_doallocate (_IO_FILE *) __THROW;
604 extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t)
605 __THROW;
606 extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t) __THROW;
607 extern wint_t _IO_wfile_sync (_IO_FILE *) __THROW;
608 extern wint_t _IO_wfile_underflow (_IO_FILE *) __THROW;
609 extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t) __THROW;
610 extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int)
611 __THROW;
613 /* Jumptable functions for proc_files. */
614 extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *)
615 __THROW;
616 extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *)
617 __THROW;
618 extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *)
619 __THROW;
620 extern int _IO_proc_close (_IO_FILE *) __THROW;
621 extern int _IO_new_proc_close (_IO_FILE *) __THROW;
622 extern int _IO_old_proc_close (_IO_FILE *) __THROW;
624 /* Jumptable functions for strfiles. */
625 extern int _IO_str_underflow (_IO_FILE *) __THROW;
626 extern int _IO_str_overflow (_IO_FILE *, int) __THROW;
627 extern int _IO_str_pbackfail (_IO_FILE *, int) __THROW;
628 extern _IO_off64_t _IO_str_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
629 extern void _IO_str_finish (_IO_FILE *, int) __THROW;
631 /* Other strfile functions */
632 struct _IO_strfile_;
633 extern void _IO_str_init_static (struct _IO_strfile_ *, char *, int, char *)
634 __THROW;
635 extern void _IO_str_init_readonly (struct _IO_strfile_ *, const char *, int)
636 __THROW;
637 extern _IO_ssize_t _IO_str_count (_IO_FILE *) __THROW;
639 /* And the wide character versions. */
640 extern void _IO_wstr_init_static (_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *)
641 __THROW;
642 extern _IO_ssize_t _IO_wstr_count (_IO_FILE *) __THROW;
643 extern _IO_wint_t _IO_wstr_overflow (_IO_FILE *, _IO_wint_t) __THROW;
644 extern _IO_wint_t _IO_wstr_underflow (_IO_FILE *) __THROW;
645 extern _IO_off64_t _IO_wstr_seekoff (_IO_FILE *, _IO_off64_t, int, int)
646 __THROW;
647 extern _IO_wint_t _IO_wstr_pbackfail (_IO_FILE *, _IO_wint_t) __THROW;
648 extern void _IO_wstr_finish (_IO_FILE *, int) __THROW;
650 extern int _IO_vasprintf (char **result_ptr, __const char *format,
651 _IO_va_list args) __THROW;
652 extern int _IO_vdprintf (int d, __const char *format, _IO_va_list arg) __THROW;
653 extern int _IO_vsnprintf (char *string, _IO_size_t maxlen,
654 __const char *format, _IO_va_list args) __THROW;
657 extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int);
658 extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t,
659 int, int, int *);
660 extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *)
661 __THROW;
662 extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int);
663 extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t,
664 wint_t, int, wint_t *);
665 extern double _IO_strtod (const char *, char **) __THROW;
666 extern char *_IO_dtoa (double __d, int __mode, int __ndigits,
667 int *__decpt, int *__sign, char **__rve) __THROW;
668 extern int _IO_outfloat (double __value, _IO_FILE *__sb, int __type,
669 int __width, int __precision, int __flags,
670 int __sign_mode, int __fill) __THROW;
672 extern struct _IO_FILE_plus *_IO_list_all;
673 extern void (*_IO_cleanup_registration_needed) (void);
675 /* Prototype for functions with alternative entry point. */
676 extern int _IO_flush_all_internal (void) __THROW;
677 extern unsigned _IO_adjust_column_internal (unsigned, const char *, int)
678 __THROW;
680 extern int _IO_default_uflow_internal (_IO_FILE *) __THROW;
681 extern void _IO_default_finish_internal (_IO_FILE *, int) __THROW;
682 extern int _IO_default_pbackfail_internal (_IO_FILE *, int) __THROW;
683 extern _IO_size_t _IO_default_xsputn_internal (_IO_FILE *, const void *,
684 _IO_size_t) __THROW;
685 extern _IO_size_t _IO_default_xsgetn_internal (_IO_FILE *, void *, _IO_size_t)
686 __THROW;
687 extern int _IO_default_doallocate_internal (_IO_FILE *) __THROW;
688 extern void _IO_wdefault_finish_internal (_IO_FILE *, int) __THROW;
689 extern wint_t _IO_wdefault_pbackfail_internal (_IO_FILE *, wint_t) __THROW;
690 extern _IO_size_t _IO_wdefault_xsputn_internal (_IO_FILE *, const void *,
691 _IO_size_t) __THROW;
692 extern _IO_size_t _IO_wdefault_xsgetn_internal (_IO_FILE *, void *,
693 _IO_size_t) __THROW;
694 extern int _IO_wdefault_doallocate_internal (_IO_FILE *) __THROW;
695 extern wint_t _IO_wdefault_uflow_internal (_IO_FILE *) __THROW;
697 extern int _IO_file_doallocate_internal (_IO_FILE *) __THROW;
698 extern _IO_FILE* _IO_file_setbuf_internal (_IO_FILE *, char *, _IO_ssize_t)
699 __THROW;
700 extern _IO_off64_t _IO_file_seekoff_internal (_IO_FILE *, _IO_off64_t,
701 int, int) __THROW;
702 extern _IO_size_t _IO_file_xsputn_internal (_IO_FILE *, const void *,
703 _IO_size_t) __THROW;
704 extern _IO_size_t _IO_file_xsgetn_internal (_IO_FILE *, void *, _IO_size_t)
705 __THROW;
706 extern int _IO_file_stat_internal (_IO_FILE *, void *) __THROW;
707 extern int _IO_file_close_internal (_IO_FILE *) __THROW;
708 extern int _IO_file_close_it_internal (_IO_FILE *) __THROW;
709 extern int _IO_file_underflow_internal (_IO_FILE *) __THROW;
710 extern int _IO_file_overflow_internal (_IO_FILE *, int) __THROW;
711 extern void _IO_file_init_internal (struct _IO_FILE_plus *) __THROW;
712 extern _IO_FILE* _IO_file_attach_internal (_IO_FILE *, int) __THROW;
713 extern _IO_FILE* _IO_file_fopen_internal (_IO_FILE *, const char *,
714 const char *, int) __THROW;
715 extern _IO_ssize_t _IO_file_read_internal (_IO_FILE *, void *,
716 _IO_ssize_t);
717 extern int _IO_file_sync_internal (_IO_FILE *) __THROW;
718 extern _IO_off64_t _IO_file_seek_internal (_IO_FILE *, _IO_off64_t, int)
719 __THROW;
720 extern void _IO_file_finish_internal (_IO_FILE *, int) __THROW;
722 extern _IO_size_t _IO_wfile_xsputn_internal (_IO_FILE *, const void *,
723 _IO_size_t) __THROW;
724 extern _IO_off64_t _IO_wfile_seekoff_internal (_IO_FILE *, _IO_off64_t,
725 int, int) __THROW;
726 extern wint_t _IO_wfile_sync_internal (_IO_FILE *) __THROW;
728 extern int _IO_str_underflow_internal (_IO_FILE *) __THROW;
729 extern int _IO_str_overflow_internal (_IO_FILE *, int) __THROW;
730 extern int _IO_str_pbackfail_internal (_IO_FILE *, int) __THROW;
731 extern _IO_off64_t _IO_str_seekoff_internal (_IO_FILE *, _IO_off64_t,
732 int, int) __THROW;
733 extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
734 _IO_size_t, char *) __THROW;
736 extern struct _IO_jump_t _IO_file_jumps_internal attribute_hidden;
737 extern struct _IO_jump_t _IO_wfile_jumps_internal attribute_hidden;
739 extern struct _IO_FILE_plus *_IO_list_all_internal attribute_hidden;
741 extern void _IO_link_in_internal (struct _IO_FILE_plus *) __THROW;
742 extern int _IO_sputbackc_internal (_IO_FILE *, int) __THROW;
743 extern void _IO_wdoallocbuf_internal (_IO_FILE *) __THROW;
745 extern _IO_size_t _IO_sgetn_internal (_IO_FILE *, void *, _IO_size_t);
746 extern void _IO_flush_all_linebuffered_internal (void) __THROW;
747 extern int _IO_switch_to_wget_mode_internal (_IO_FILE *) __THROW;
748 extern void _IO_unsave_markers_internal (_IO_FILE *) __THROW;
749 extern void _IO_switch_to_main_wget_area_internal (_IO_FILE *) __THROW;
750 extern int _IO_wdo_write_internal (_IO_FILE *, const wchar_t *, _IO_size_t);
751 extern int _IO_do_write_internal (_IO_FILE *, const char *, _IO_size_t);
752 extern _IO_ssize_t _IO_padn_internal (_IO_FILE *, int, _IO_ssize_t) __THROW;
753 extern _IO_size_t _IO_getline_info_internal (_IO_FILE *,char *, _IO_size_t,
754 int, int, int *);
755 extern _IO_size_t _IO_getline_internal (_IO_FILE *, char *, _IO_size_t, int,
756 int);
757 extern void _IO_free_wbackup_area_internal (_IO_FILE *) __THROW;
758 extern void _IO_free_backup_area_internal (_IO_FILE *) __THROW;
759 extern void _IO_switch_to_wbackup_area_internal (_IO_FILE *) __THROW;
760 extern void _IO_setb_internal (_IO_FILE *, char *, char *, int) __THROW;
761 extern wint_t _IO_sputbackwc_internal (_IO_FILE *, wint_t) __THROW;
762 extern int _IO_switch_to_get_mode_internal (_IO_FILE *) __THROW;
763 extern int _IO_vfscanf_internal (_IO_FILE * __restrict,
764 const char * __restrict,
765 _IO_va_list, int *__restrict);
766 extern int _IO_vfprintf_internal (_IO_FILE *__restrict, const char *__restrict,
767 _IO_va_list);
768 extern void _IO_doallocbuf_internal (_IO_FILE *) __THROW;
769 extern void _IO_wsetb_internal (_IO_FILE *, wchar_t *, wchar_t *, int)
770 __THROW;
771 extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
772 attribute_hidden __THROW;
773 extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
774 attribute_hidden __THROW;
775 extern int _IO_putc_internal (int __c, _IO_FILE *__fp);
776 extern void _IO_init_internal (_IO_FILE *, int) __THROW;
777 extern void _IO_un_link_internal (struct _IO_FILE_plus *) __THROW;
779 #ifndef EOF
780 # define EOF (-1)
781 #endif
782 #ifndef NULL
783 # if defined __GNUG__ && \
784 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
785 # define NULL (__null)
786 # else
787 # if !defined(__cplusplus)
788 # define NULL ((void*)0)
789 # else
790 # define NULL (0)
791 # endif
792 # endif
793 #endif
795 #if _G_HAVE_MMAP
797 # include <unistd.h>
798 # include <fcntl.h>
799 # include <sys/mman.h>
800 # include <sys/param.h>
802 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
803 # define MAP_ANONYMOUS MAP_ANON
804 # endif
806 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
807 # undef _G_HAVE_MMAP
808 # define _G_HAVE_MMAP 0
809 # endif
811 #endif /* _G_HAVE_MMAP */
813 #if _G_HAVE_MMAP
815 # ifdef _LIBC
816 /* When using this code in the GNU libc we must not pollute the name space. */
817 # define mmap __mmap
818 # define munmap __munmap
819 # define ftruncate __ftruncate
820 # endif
822 # define ROUND_TO_PAGE(_S) \
823 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
825 # define FREE_BUF(_B, _S) \
826 munmap ((_B), ROUND_TO_PAGE (_S))
827 # define ALLOC_BUF(_B, _S, _R) \
828 do { \
829 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
830 PROT_READ | PROT_WRITE, \
831 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
832 if ((_B) == (char *) MAP_FAILED) \
833 return (_R); \
834 } while (0)
835 # define ALLOC_WBUF(_B, _S, _R) \
836 do { \
837 (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
838 PROT_READ | PROT_WRITE, \
839 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
840 if ((_B) == (wchar_t *) MAP_FAILED) \
841 return (_R); \
842 } while (0)
844 #else /* _G_HAVE_MMAP */
846 # define FREE_BUF(_B, _S) \
847 free(_B)
848 # define ALLOC_BUF(_B, _S, _R) \
849 do { \
850 (_B) = (char*)malloc(_S); \
851 if ((_B) == NULL) \
852 return (_R); \
853 } while (0)
854 # define ALLOC_WBUF(_B, _S, _R) \
855 do { \
856 (_B) = (wchar_t *)malloc(_S); \
857 if ((_B) == NULL) \
858 return (_R); \
859 } while (0)
861 #endif /* _G_HAVE_MMAP */
863 #ifndef OS_FSTAT
864 # define OS_FSTAT fstat
865 #endif
866 struct stat;
867 extern _IO_ssize_t _IO_read (int, void *, _IO_size_t);
868 extern _IO_ssize_t _IO_write (int, const void *, _IO_size_t);
869 extern _IO_off64_t _IO_lseek (int, _IO_off64_t, int) __THROW;
870 extern int _IO_close (int);
871 extern int _IO_fstat (int, struct stat *) __THROW;
872 extern int _IO_vscanf (const char *, _IO_va_list) __THROW;
874 /* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
875 #ifndef _IO_pos_BAD
876 # define _IO_pos_BAD ((_IO_off64_t) -1)
877 #endif
878 /* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
879 #ifndef _IO_pos_adjust
880 # define _IO_pos_adjust(pos, delta) ((pos) += (delta))
881 #endif
882 /* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
883 #ifndef _IO_pos_0
884 # define _IO_pos_0 ((_IO_off64_t) 0)
885 #endif
887 #ifdef __cplusplus
889 #endif
891 #ifdef _IO_MTSAFE_IO
892 /* check following! */
893 # ifdef _IO_USE_OLD_IO_FILE
894 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
895 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
896 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
897 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
898 # else
899 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
900 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
901 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
902 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
903 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
904 NULL, WDP, 0 }
905 # else
906 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
907 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
908 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
909 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
911 # endif
912 # endif
913 #else
914 # ifdef _IO_USE_OLD_IO_FILE
915 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
916 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
917 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
918 0, _IO_pos_BAD }
919 # else
920 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
921 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
922 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
923 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
924 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
925 NULL, WDP, 0 }
926 # else
927 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
928 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
929 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
930 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
932 # endif
933 # endif
934 #endif
936 /* VTABLE_LABEL defines NAME as of the CLASS class.
937 CNLENGTH is strlen(#CLASS). */
938 #ifdef __GNUC__
939 # if _G_VTABLE_LABEL_HAS_LENGTH
940 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
941 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CNLENGTH #CLASS);
942 # else
943 # define VTABLE_LABEL(NAME, CLASS, CNLENGTH) \
944 extern char NAME[] asm (_G_VTABLE_LABEL_PREFIX #CLASS);
945 # endif
946 #endif /* __GNUC__ */
948 #if !defined(builtinbuf_vtable) && defined(__cplusplus)
949 # ifdef __GNUC__
950 VTABLE_LABEL(builtinbuf_vtable, builtinbuf, 10)
951 # else
952 # if _G_VTABLE_LABEL_HAS_LENGTH
953 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##10builtinbuf
954 # else
955 # define builtinbuf_vtable _G_VTABLE_LABEL_PREFIX_ID##builtinbuf
956 # endif
957 # endif
958 #endif /* !defined(builtinbuf_vtable) && defined(__cplusplus) */
960 #if defined(__STDC__) || defined(__cplusplus)
961 # define _IO_va_start(args, last) va_start(args, last)
962 #else
963 # define _IO_va_start(args, last) va_start(args)
964 #endif
966 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
968 #if 1
969 # define COERCE_FILE(FILE) /* Nothing */
970 #else
971 /* This is part of the kludge for binary compatibility with old stdio. */
972 # define COERCE_FILE(FILE) \
973 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
974 && (FILE) = *(FILE**)&((int*)fp)[1])
975 #endif
977 #ifdef EINVAL
978 # define MAYBE_SET_EINVAL __set_errno (EINVAL)
979 #else
980 # define MAYBE_SET_EINVAL /* nothing */
981 #endif
983 #ifdef IO_DEBUG
984 # define CHECK_FILE(FILE, RET) \
985 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
986 else { COERCE_FILE(FILE); \
987 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
988 { MAYBE_SET_EINVAL; return RET; }}
989 #else
990 # define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
991 #endif
993 static inline void
994 __attribute__ ((__always_inline__))
995 _IO_acquire_lock_fct (_IO_FILE **p)
997 _IO_FILE *fp = *p;
998 if ((fp->_flags & _IO_USER_LOCK) == 0)
999 _IO_funlockfile (fp);