]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/libioP.h
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / libio / libioP.h
CommitLineData
d4697bc9 1/* Copyright (C) 1993-2014 Free Software Foundation, Inc.
41bdb6e2 2 This file is part of the GNU C Library.
40a55d20 3
41bdb6e2
AJ
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.
40a55d20 8
41bdb6e2
AJ
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
40a55d20 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2
AJ
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>.
41bdb6e2
AJ
17
18 As a special exception, if you link the code in this file with
19 files compiled with a GNU compiler to produce an executable,
20 that does not cause the resulting executable to be covered by
21 the GNU Lesser General Public License. This exception does not
22 however invalidate any other reasons why the executable file
23 might be covered by the GNU Lesser General Public License.
24 This exception applies to code released by its copyright holders
25 in files containing the exception. */
96aa2d94 26
b1848fde
SP
27/* NOTE: libio is now exclusively used only by glibc since libstdc++ has its
28 own implementation. As a result, functions that were implemented for C++
29 (like *sputn) may no longer have C++ semantics. This is of course only
30 relevant for internal callers of these functions since these functions are
31 not intended for external use otherwise.
32
33 FIXME: All of the C++ cruft eventually needs to go away. */
34
96aa2d94 35#include <errno.h>
a2b08ee5
UD
36#ifndef __set_errno
37# define __set_errno(Val) errno = (Val)
38#endif
39#if defined __GLIBC__ && __GLIBC__ >= 2
40# include <bits/libc-lock.h>
41#else
42/*# include <comthread.h>*/
43#endif
96aa2d94 44
c6251f03
RM
45#include <math_ldbl_opt.h>
46
96aa2d94
RM
47#include "iolibio.h"
48
77fe0b9c
UD
49/* Control of exported symbols. Used in glibc. By default we don't
50 do anything. */
37ba7d66
UD
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
60
4547c1a4
UD
61#ifdef __cplusplus
62extern "C" {
63#endif
96aa2d94
RM
64
65#define _IO_seek_set 0
66#define _IO_seek_cur 1
67#define _IO_seek_end 2
68
f65fd747
UD
69/* THE JUMPTABLE FUNCTIONS.
70
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
c0c3f78a 76 * with the _IO_JUMPS macro. The jump table has an eccentric format,
f65fd747 77 * so as to be compatible with the layout of a C++ virtual function table.
6d52618b 78 * (as implemented by g++). When a pointer to a streambuf object is
f65fd747
UD
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
6d52618b 82 * double duty as the virtual function table for C++ streambuf.
f65fd747
UD
83 *
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).
88 */
96aa2d94 89
00404a96
RM
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
99
bd355af0
UD
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
104
2ca8b1ee 105#define _IO_JUMPS(THIS) (THIS)->vtable
d64b6ad0 106#define _IO_WIDE_JUMPS(THIS) ((struct _IO_FILE *) (THIS))->_wide_data->_wide_vtable
7163e69e
UD
107#define _IO_CHECK_WIDE(THIS) (((struct _IO_FILE *) (THIS))->_wide_data != NULL)
108
bd355af0
UD
109#if _IO_JUMPS_OFFSET
110# define _IO_JUMPS_FUNC(THIS) \
2ca8b1ee 111 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS ((struct _IO_FILE_plus *) (THIS)) \
bd355af0 112 + (THIS)->_vtable_offset))
bbdef797 113# define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
bd355af0 114#else
2ca8b1ee 115# define _IO_JUMPS_FUNC(THIS) _IO_JUMPS ((struct _IO_FILE_plus *) (THIS))
bbdef797 116# define _IO_vtable_offset(THIS) 0
bd355af0 117#endif
6e06ae59 118#define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
28361c5e
JM
119#define JUMP_FIELD(TYPE, NAME) TYPE NAME
120#define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
121#define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
122#define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
123#define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
124#define JUMP_INIT(NAME, VALUE) VALUE
125#define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
126
127#define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
128#define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
129#define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
130#define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
96aa2d94 131
f65fd747 132/* The 'finish' function does any final cleaning up of an _IO_FILE object.
110215a9 133 It does not delete (free) it, but does everything else to finalize it.
f65fd747 134 It matches the streambuf::~streambuf virtual destructor. */
79937577 135typedef void (*_IO_finish_t) (_IO_FILE *, int); /* finalize */
40a55d20 136#define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
6e06ae59 137#define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
f65fd747
UD
138
139/* The 'overflow' hook flushes the buffer.
140 The second argument is a character, or EOF.
141 It matches the streambuf::overflow virtual function. */
79937577 142typedef int (*_IO_overflow_t) (_IO_FILE *, int);
40a55d20 143#define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
6e06ae59 144#define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
f65fd747
UD
145
146/* The 'underflow' hook tries to fills the get buffer.
147 It returns the next character (as an unsigned char) or EOF. The next
6d52618b 148 character remains in the get buffer, and the get position is not changed.
f65fd747 149 It matches the streambuf::underflow virtual function. */
79937577 150typedef int (*_IO_underflow_t) (_IO_FILE *);
40a55d20 151#define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
6e06ae59 152#define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
f65fd747
UD
153
154/* The 'uflow' hook returns the next character in the input stream
155 (cast to unsigned char), and increments the read position;
156 EOF is returned on failure.
157 It matches the streambuf::uflow virtual function, which is not in the
158 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
40a55d20 159#define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
6e06ae59 160#define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
f65fd747
UD
161
162/* The 'pbackfail' hook handles backing up.
163 It matches the streambuf::pbackfail virtual function. */
79937577 164typedef int (*_IO_pbackfail_t) (_IO_FILE *, int);
40a55d20 165#define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
6e06ae59 166#define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
f65fd747
UD
167
168/* The 'xsputn' hook writes upto N characters from buffer DATA.
2b766585 169 Returns EOF or the number of character actually written.
f65fd747 170 It matches the streambuf::xsputn virtual function. */
79937577
UD
171typedef _IO_size_t (*_IO_xsputn_t) (_IO_FILE *FP, const void *DATA,
172 _IO_size_t N);
40a55d20 173#define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
6e06ae59 174#define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
f65fd747
UD
175
176/* The 'xsgetn' hook reads upto N characters into buffer DATA.
177 Returns the number of character actually read.
178 It matches the streambuf::xsgetn virtual function. */
79937577 179typedef _IO_size_t (*_IO_xsgetn_t) (_IO_FILE *FP, void *DATA, _IO_size_t N);
40a55d20 180#define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
6e06ae59 181#define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
f65fd747
UD
182
183/* The 'seekoff' hook moves the stream position to a new position
184 relative to the start of the file (if DIR==0), the current position
185 (MODE==1), or the end of the file (MODE==2).
186 It matches the streambuf::seekoff virtual function.
187 It is also used for the ANSI fseek function. */
79937577
UD
188typedef _IO_off64_t (*_IO_seekoff_t) (_IO_FILE *FP, _IO_off64_t OFF, int DIR,
189 int MODE);
40a55d20 190#define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
6e06ae59 191#define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
f65fd747
UD
192
193/* The 'seekpos' hook also moves the stream position,
dfd2257a 194 but to an absolute position given by a fpos64_t (seekpos).
f65fd747
UD
195 It matches the streambuf::seekpos virtual function.
196 It is also used for the ANSI fgetpos and fsetpos functions. */
197/* The _IO_seek_cur and _IO_seek_end options are not allowed. */
79937577 198typedef _IO_off64_t (*_IO_seekpos_t) (_IO_FILE *, _IO_off64_t, int);
40a55d20 199#define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
6e06ae59 200#define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
f65fd747
UD
201
202/* The 'setbuf' hook gives a buffer to the file.
203 It matches the streambuf::setbuf virtual function. */
79937577 204typedef _IO_FILE* (*_IO_setbuf_t) (_IO_FILE *, char *, _IO_ssize_t);
40a55d20 205#define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
6e06ae59 206#define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
f65fd747
UD
207
208/* The 'sync' hook attempts to synchronize the internal data structures
209 of the file with the external state.
210 It matches the streambuf::sync virtual function. */
79937577 211typedef int (*_IO_sync_t) (_IO_FILE *);
40a55d20 212#define _IO_SYNC(FP) JUMP0 (__sync, FP)
6e06ae59 213#define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
f65fd747
UD
214
215/* The 'doallocate' hook is used to tell the file to allocate a buffer.
216 It matches the streambuf::doallocate virtual function, which is not
217 in the ANSI/ISO C++ standard, but is part traditional implementations. */
79937577 218typedef int (*_IO_doallocate_t) (_IO_FILE *);
40a55d20 219#define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
6e06ae59 220#define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
f65fd747
UD
221
222/* The following four hooks (sysread, syswrite, sysclose, sysseek, and
223 sysstat) are low-level hooks specific to this implementation.
6d52618b 224 There is no correspondence in the ANSI/ISO C++ standard library.
f65fd747
UD
225 The hooks basically correspond to the Unix system functions
226 (read, write, close, lseek, and stat) except that a _IO_FILE*
c0c3f78a 227 parameter is used instead of an integer file descriptor; the default
f65fd747
UD
228 implementation used for normal files just calls those functions.
229 The advantage of overriding these functions instead of the higher-level
230 ones (underflow, overflow etc) is that you can leave all the buffering
231 higher-level functions. */
232
233/* The 'sysread' hook is used to read data from the external file into
234 an existing buffer. It generalizes the Unix read(2) function.
235 It matches the streambuf::sys_read virtual function, which is
6d52618b 236 specific to this implementation. */
79937577 237typedef _IO_ssize_t (*_IO_read_t) (_IO_FILE *, void *, _IO_ssize_t);
40a55d20 238#define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
6e06ae59 239#define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
f65fd747
UD
240
241/* The 'syswrite' hook is used to write data from an existing buffer
242 to an external file. It generalizes the Unix write(2) function.
243 It matches the streambuf::sys_write virtual function, which is
6d52618b 244 specific to this implementation. */
79937577 245typedef _IO_ssize_t (*_IO_write_t) (_IO_FILE *, const void *, _IO_ssize_t);
40a55d20 246#define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
6e06ae59 247#define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
f65fd747
UD
248
249/* The 'sysseek' hook is used to re-position an external file.
250 It generalizes the Unix lseek(2) function.
251 It matches the streambuf::sys_seek virtual function, which is
6d52618b 252 specific to this implementation. */
79937577 253typedef _IO_off64_t (*_IO_seek_t) (_IO_FILE *, _IO_off64_t, int);
40a55d20 254#define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
6e06ae59 255#define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
f65fd747
UD
256
257/* The 'sysclose' hook is used to finalize (close, finish up) an
258 external file. It generalizes the Unix close(2) function.
259 It matches the streambuf::sys_close virtual function, which is
260 specific to this implementation. */
79937577 261typedef int (*_IO_close_t) (_IO_FILE *); /* finalize */
40a55d20 262#define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
6e06ae59 263#define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
f65fd747
UD
264
265/* The 'sysstat' hook is used to get information about an external file
266 into a struct stat buffer. It generalizes the Unix fstat(2) call.
267 It matches the streambuf::sys_stat virtual function, which is
6d52618b 268 specific to this implementation. */
79937577 269typedef int (*_IO_stat_t) (_IO_FILE *, void *);
40a55d20 270#define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
6e06ae59 271#define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
96aa2d94 272
dfd2257a
UD
273/* The 'showmany' hook can be used to get an image how much input is
274 available. In many cases the answer will be 0 which means unknown
275 but some cases one can provide real information. */
79937577 276typedef int (*_IO_showmanyc_t) (_IO_FILE *);
dfd2257a 277#define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
6e06ae59 278#define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
dfd2257a
UD
279
280/* The 'imbue' hook is used to get information about the currently
281 installed locales. */
79937577 282typedef void (*_IO_imbue_t) (_IO_FILE *, void *);
dfd2257a 283#define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
6e06ae59 284#define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
dfd2257a 285
f65fd747 286
96aa2d94
RM
287#define _IO_CHAR_TYPE char /* unsigned char ? */
288#define _IO_INT_TYPE int
289
40a55d20
UD
290struct _IO_jump_t
291{
203e5603
JM
292 JUMP_FIELD(size_t, __dummy);
293 JUMP_FIELD(size_t, __dummy2);
96aa2d94
RM
294 JUMP_FIELD(_IO_finish_t, __finish);
295 JUMP_FIELD(_IO_overflow_t, __overflow);
296 JUMP_FIELD(_IO_underflow_t, __underflow);
297 JUMP_FIELD(_IO_underflow_t, __uflow);
298 JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
299 /* showmany */
300 JUMP_FIELD(_IO_xsputn_t, __xsputn);
301 JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
302 JUMP_FIELD(_IO_seekoff_t, __seekoff);
303 JUMP_FIELD(_IO_seekpos_t, __seekpos);
304 JUMP_FIELD(_IO_setbuf_t, __setbuf);
305 JUMP_FIELD(_IO_sync_t, __sync);
306 JUMP_FIELD(_IO_doallocate_t, __doallocate);
307 JUMP_FIELD(_IO_read_t, __read);
308 JUMP_FIELD(_IO_write_t, __write);
309 JUMP_FIELD(_IO_seek_t, __seek);
310 JUMP_FIELD(_IO_close_t, __close);
311 JUMP_FIELD(_IO_stat_t, __stat);
dfd2257a
UD
312 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
313 JUMP_FIELD(_IO_imbue_t, __imbue);
96aa2d94
RM
314#if 0
315 get_column;
316 set_column;
317#endif
318};
319
320/* We always allocate an extra word following an _IO_FILE.
f65fd747 321 This contains a pointer to the function jump table used.
96aa2d94
RM
322 This is for compatibility with C++ streambuf; the word can
323 be used to smash to a pointer to a virtual function table. */
324
40a55d20
UD
325struct _IO_FILE_plus
326{
96aa2d94 327 _IO_FILE file;
96aa2d94 328 const struct _IO_jump_t *vtable;
96aa2d94
RM
329};
330
7ea11363
UD
331#ifdef _IO_USE_OLD_IO_FILE
332/* This structure is used by the compatibility code as if it were an
333 _IO_FILE_plus, but has enough space to initialize the _mode argument
334 of an _IO_FILE_complete. */
335struct _IO_FILE_complete_plus
336{
337 struct _IO_FILE_complete file;
338 const struct _IO_jump_t *vtable;
339};
340#endif
341
2ca8b1ee
GM
342/* Special file type for fopencookie function. */
343struct _IO_cookie_file
344{
345 struct _IO_FILE_plus __fp;
346 void *__cookie;
347 _IO_cookie_io_functions_t __io_functions;
348};
349
c9fc9559
RM
350_IO_FILE *_IO_fopencookie (void *cookie, const char *mode,
351 _IO_cookie_io_functions_t io_functions);
352
353
3fc9ca4e
UD
354/* Iterator type for walking global linked list of _IO_FILE objects. */
355
73c115ed 356typedef struct _IO_FILE *_IO_ITER;
3fc9ca4e 357
96aa2d94
RM
358/* Generic functions */
359
79937577
UD
360extern void _IO_switch_to_main_get_area (_IO_FILE *) __THROW;
361extern void _IO_switch_to_backup_area (_IO_FILE *) __THROW;
0fca3153 362extern int _IO_switch_to_get_mode (_IO_FILE *);
d18ea0c5 363libc_hidden_proto (_IO_switch_to_get_mode)
79937577 364extern void _IO_init (_IO_FILE *, int) __THROW;
d18ea0c5 365libc_hidden_proto (_IO_init)
79937577 366extern int _IO_sputbackc (_IO_FILE *, int) __THROW;
d18ea0c5 367libc_hidden_proto (_IO_sputbackc)
79937577
UD
368extern int _IO_sungetc (_IO_FILE *) __THROW;
369extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
d18ea0c5 370libc_hidden_proto (_IO_un_link)
79937577 371extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
d18ea0c5 372libc_hidden_proto (_IO_link_in)
79937577 373extern void _IO_doallocbuf (_IO_FILE *) __THROW;
d18ea0c5 374libc_hidden_proto (_IO_doallocbuf)
79937577 375extern void _IO_unsave_markers (_IO_FILE *) __THROW;
d18ea0c5 376libc_hidden_proto (_IO_unsave_markers)
79937577 377extern void _IO_setb (_IO_FILE *, char *, char *, int) __THROW;
d18ea0c5 378libc_hidden_proto (_IO_setb)
79937577 379extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
d18ea0c5 380libc_hidden_proto (_IO_adjust_column)
40a55d20 381#define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
96aa2d94 382
d18ea0c5
AS
383_IO_ssize_t _IO_least_wmarker (_IO_FILE *, wchar_t *) __THROW;
384libc_hidden_proto (_IO_least_wmarker)
79937577 385extern void _IO_switch_to_main_wget_area (_IO_FILE *) __THROW;
d18ea0c5 386libc_hidden_proto (_IO_switch_to_main_wget_area)
79937577 387extern void _IO_switch_to_wbackup_area (_IO_FILE *) __THROW;
d18ea0c5 388libc_hidden_proto (_IO_switch_to_wbackup_area)
0fca3153 389extern int _IO_switch_to_wget_mode (_IO_FILE *);
d18ea0c5 390libc_hidden_proto (_IO_switch_to_wget_mode)
79937577 391extern void _IO_wsetb (_IO_FILE *, wchar_t *, wchar_t *, int) __THROW;
d18ea0c5 392libc_hidden_proto (_IO_wsetb)
79937577 393extern wint_t _IO_sputbackwc (_IO_FILE *, wint_t) __THROW;
d18ea0c5 394libc_hidden_proto (_IO_sputbackwc)
79937577
UD
395extern wint_t _IO_sungetwc (_IO_FILE *) __THROW;
396extern void _IO_wdoallocbuf (_IO_FILE *) __THROW;
d18ea0c5 397libc_hidden_proto (_IO_wdoallocbuf)
79937577
UD
398extern void _IO_unsave_wmarkers (_IO_FILE *) __THROW;
399extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
d64b6ad0 400
96aa2d94
RM
401/* Marker-related function. */
402
0fca3153
UD
403extern void _IO_init_marker (struct _IO_marker *, _IO_FILE *);
404extern void _IO_init_wmarker (struct _IO_marker *, _IO_FILE *);
79937577
UD
405extern void _IO_remove_marker (struct _IO_marker *) __THROW;
406extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
407 __THROW;
408extern int _IO_marker_delta (struct _IO_marker *) __THROW;
409extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
410extern int _IO_seekmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
411extern int _IO_seekwmark (_IO_FILE *, struct _IO_marker *, int) __THROW;
96aa2d94 412
79937577 413/* Functions for iterating global list and dealing with its lock */
3fc9ca4e 414
79937577 415extern _IO_ITER _IO_iter_begin (void) __THROW;
1d2b6e0c 416libc_hidden_proto (_IO_iter_begin)
79937577 417extern _IO_ITER _IO_iter_end (void) __THROW;
1d2b6e0c 418libc_hidden_proto (_IO_iter_end)
79937577 419extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
1d2b6e0c 420libc_hidden_proto (_IO_iter_next)
79937577 421extern _IO_FILE *_IO_iter_file (_IO_ITER) __THROW;
1d2b6e0c 422libc_hidden_proto (_IO_iter_file)
79937577 423extern void _IO_list_lock (void) __THROW;
245eab02 424libc_hidden_proto (_IO_list_lock)
79937577 425extern void _IO_list_unlock (void) __THROW;
245eab02 426libc_hidden_proto (_IO_list_unlock)
79937577 427extern void _IO_list_resetlock (void) __THROW;
245eab02 428libc_hidden_proto (_IO_list_resetlock)
3fc9ca4e 429
96aa2d94
RM
430/* Default jumptable functions. */
431
79937577 432extern int _IO_default_underflow (_IO_FILE *) __THROW;
0fca3153 433extern int _IO_default_uflow (_IO_FILE *);
d18ea0c5 434libc_hidden_proto (_IO_default_uflow)
0fca3153 435extern wint_t _IO_wdefault_uflow (_IO_FILE *);
d18ea0c5 436libc_hidden_proto (_IO_wdefault_uflow)
79937577 437extern int _IO_default_doallocate (_IO_FILE *) __THROW;
d18ea0c5 438libc_hidden_proto (_IO_default_doallocate)
79937577 439extern int _IO_wdefault_doallocate (_IO_FILE *) __THROW;
d18ea0c5 440libc_hidden_proto (_IO_wdefault_doallocate)
79937577 441extern void _IO_default_finish (_IO_FILE *, int) __THROW;
d18ea0c5 442libc_hidden_proto (_IO_default_finish)
79937577 443extern void _IO_wdefault_finish (_IO_FILE *, int) __THROW;
d18ea0c5 444libc_hidden_proto (_IO_wdefault_finish)
79937577 445extern int _IO_default_pbackfail (_IO_FILE *, int) __THROW;
d18ea0c5 446libc_hidden_proto (_IO_default_pbackfail)
79937577 447extern wint_t _IO_wdefault_pbackfail (_IO_FILE *, wint_t) __THROW;
d18ea0c5 448libc_hidden_proto (_IO_wdefault_pbackfail)
0fca3153 449extern _IO_FILE* _IO_default_setbuf (_IO_FILE *, char *, _IO_ssize_t);
102070bc 450extern _IO_size_t _IO_default_xsputn (_IO_FILE *, const void *, _IO_size_t);
d18ea0c5 451libc_hidden_proto (_IO_default_xsputn)
102070bc 452extern _IO_size_t _IO_wdefault_xsputn (_IO_FILE *, const void *, _IO_size_t);
d18ea0c5 453libc_hidden_proto (_IO_wdefault_xsputn)
102070bc 454extern _IO_size_t _IO_default_xsgetn (_IO_FILE *, void *, _IO_size_t);
d18ea0c5 455libc_hidden_proto (_IO_default_xsgetn)
102070bc 456extern _IO_size_t _IO_wdefault_xsgetn (_IO_FILE *, void *, _IO_size_t);
d18ea0c5 457libc_hidden_proto (_IO_wdefault_xsgetn)
79937577
UD
458extern _IO_off64_t _IO_default_seekoff (_IO_FILE *, _IO_off64_t, int, int)
459 __THROW;
0fca3153 460extern _IO_off64_t _IO_default_seekpos (_IO_FILE *, _IO_off64_t, int);
102070bc
UD
461extern _IO_ssize_t _IO_default_write (_IO_FILE *, const void *, _IO_ssize_t);
462extern _IO_ssize_t _IO_default_read (_IO_FILE *, void *, _IO_ssize_t);
79937577
UD
463extern int _IO_default_stat (_IO_FILE *, void *) __THROW;
464extern _IO_off64_t _IO_default_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
465extern int _IO_default_sync (_IO_FILE *) __THROW;
40a55d20 466#define _IO_default_close ((_IO_close_t) _IO_default_sync)
79937577
UD
467extern int _IO_default_showmanyc (_IO_FILE *) __THROW;
468extern void _IO_default_imbue (_IO_FILE *, void *) __THROW;
96aa2d94 469
b2637a22 470extern const struct _IO_jump_t _IO_file_jumps;
15a686af 471libc_hidden_proto (_IO_file_jumps)
b2637a22
UD
472extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
473extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
474extern const struct _IO_jump_t _IO_wfile_jumps;
15a686af 475libc_hidden_proto (_IO_wfile_jumps)
b2637a22
UD
476extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
477extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
478extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
479extern const struct _IO_jump_t _IO_streambuf_jumps;
480extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
481extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
482extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
97d261ad 483extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
0fca3153 484extern int _IO_do_write (_IO_FILE *, const char *, _IO_size_t);
d18ea0c5 485libc_hidden_proto (_IO_do_write)
0fca3153
UD
486extern int _IO_new_do_write (_IO_FILE *, const char *, _IO_size_t);
487extern int _IO_old_do_write (_IO_FILE *, const char *, _IO_size_t);
488extern int _IO_wdo_write (_IO_FILE *, const wchar_t *, _IO_size_t);
d18ea0c5 489libc_hidden_proto (_IO_wdo_write)
0fca3153
UD
490extern int _IO_flush_all_lockp (int);
491extern int _IO_flush_all (void);
d18ea0c5 492libc_hidden_proto (_IO_flush_all)
0fca3153
UD
493extern int _IO_cleanup (void);
494extern void _IO_flush_all_linebuffered (void);
d18ea0c5 495libc_hidden_proto (_IO_flush_all_linebuffered)
0fca3153
UD
496extern int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *);
497extern int _IO_old_fgetpos (_IO_FILE *, _IO_fpos_t *);
498extern int _IO_new_fsetpos (_IO_FILE *, const _IO_fpos_t *);
499extern int _IO_old_fsetpos (_IO_FILE *, const _IO_fpos_t *);
500extern int _IO_new_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
501extern int _IO_old_fgetpos64 (_IO_FILE *, _IO_fpos64_t *);
502extern int _IO_new_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
503extern int _IO_old_fsetpos64 (_IO_FILE *, const _IO_fpos64_t *);
79937577 504extern void _IO_old_init (_IO_FILE *fp, int flags) __THROW;
d64b6ad0 505
96aa2d94 506
319d719d
UD
507#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
508# define _IO_do_flush(_f) \
d64b6ad0 509 ((_f)->_mode <= 0 \
d18ea0c5
AS
510 ? _IO_do_write(_f, (_f)->_IO_write_base, \
511 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
512 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
513 ((_f)->_wide_data->_IO_write_ptr \
514 - (_f)->_wide_data->_IO_write_base)))
319d719d
UD
515#else
516# define _IO_do_flush(_f) \
d18ea0c5
AS
517 _IO_do_write(_f, (_f)->_IO_write_base, \
518 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
319d719d 519#endif
6973fc01
UD
520#define _IO_old_do_flush(_f) \
521 _IO_old_do_write(_f, (_f)->_IO_write_base, \
522 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
96aa2d94
RM
523#define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
524#define _IO_mask_flags(fp, f, mask) \
525 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
526#define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
527 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
d64b6ad0
UD
528#define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
529 (fp)->_wide_data->_IO_read_ptr = (g), \
530 (fp)->_wide_data->_IO_read_end = (eg))
96aa2d94 531#define _IO_setp(__fp, __p, __ep) \
d64b6ad0
UD
532 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
533 = __p, (__fp)->_IO_write_end = (__ep))
534#define _IO_wsetp(__fp, __p, __ep) \
535 ((__fp)->_wide_data->_IO_write_base \
536 = (__fp)->_wide_data->_IO_write_ptr = __p, \
537 (__fp)->_wide_data->_IO_write_end = (__ep))
96aa2d94 538#define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
d64b6ad0 539#define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
96aa2d94
RM
540#define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
541#define _IO_have_markers(fp) ((fp)->_markers != NULL)
f65fd747 542#define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
d64b6ad0
UD
543#define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
544 - (fp)->_wide_data->_IO_buf_base)
96aa2d94
RM
545
546/* Jumptable functions for files. */
547
79937577 548extern int _IO_file_doallocate (_IO_FILE *) __THROW;
d18ea0c5 549libc_hidden_proto (_IO_file_doallocate)
0fca3153 550extern _IO_FILE* _IO_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
d18ea0c5 551libc_hidden_proto (_IO_file_setbuf)
0fca3153 552extern _IO_off64_t _IO_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
d18ea0c5 553libc_hidden_proto (_IO_file_seekoff)
79937577
UD
554extern _IO_off64_t _IO_file_seekoff_mmap (_IO_FILE *, _IO_off64_t, int, int)
555 __THROW;
0fca3153 556extern _IO_size_t _IO_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
d18ea0c5 557libc_hidden_proto (_IO_file_xsputn)
0fca3153 558extern _IO_size_t _IO_file_xsgetn (_IO_FILE *, void *, _IO_size_t);
d18ea0c5 559libc_hidden_proto (_IO_file_xsgetn)
79937577 560extern int _IO_file_stat (_IO_FILE *, void *) __THROW;
d18ea0c5 561libc_hidden_proto (_IO_file_stat)
79937577 562extern int _IO_file_close (_IO_FILE *) __THROW;
d18ea0c5 563libc_hidden_proto (_IO_file_close)
79937577 564extern int _IO_file_close_mmap (_IO_FILE *) __THROW;
0fca3153 565extern int _IO_file_underflow (_IO_FILE *);
d18ea0c5 566libc_hidden_proto (_IO_file_underflow)
0fca3153
UD
567extern int _IO_file_underflow_mmap (_IO_FILE *);
568extern int _IO_file_underflow_maybe_mmap (_IO_FILE *);
569extern int _IO_file_overflow (_IO_FILE *, int);
d18ea0c5 570libc_hidden_proto (_IO_file_overflow)
110215a9 571#define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
79937577 572extern void _IO_file_init (struct _IO_FILE_plus *) __THROW;
d18ea0c5 573libc_hidden_proto (_IO_file_init)
0fca3153 574extern _IO_FILE* _IO_file_attach (_IO_FILE *, int);
d18ea0c5 575libc_hidden_proto (_IO_file_attach)
0fca3153 576extern _IO_FILE* _IO_file_open (_IO_FILE *, const char *, int, int, int, int);
ee2a5ae8 577libc_hidden_proto (_IO_file_open)
0fca3153 578extern _IO_FILE* _IO_file_fopen (_IO_FILE *, const char *, const char *, int);
d18ea0c5 579libc_hidden_proto (_IO_file_fopen)
0fca3153
UD
580extern _IO_ssize_t _IO_file_write (_IO_FILE *, const void *, _IO_ssize_t);
581extern _IO_ssize_t _IO_file_read (_IO_FILE *, void *, _IO_ssize_t);
d18ea0c5 582libc_hidden_proto (_IO_file_read)
0fca3153 583extern int _IO_file_sync (_IO_FILE *);
d18ea0c5 584libc_hidden_proto (_IO_file_sync)
0fca3153 585extern int _IO_file_close_it (_IO_FILE *);
d18ea0c5 586libc_hidden_proto (_IO_file_close_it)
79937577 587extern _IO_off64_t _IO_file_seek (_IO_FILE *, _IO_off64_t, int) __THROW;
d18ea0c5 588libc_hidden_proto (_IO_file_seek)
0fca3153 589extern void _IO_file_finish (_IO_FILE *, int);
d18ea0c5 590libc_hidden_proto (_IO_file_finish)
79937577 591
0fca3153
UD
592extern _IO_FILE* _IO_new_file_attach (_IO_FILE *, int);
593extern int _IO_new_file_close_it (_IO_FILE *);
594extern void _IO_new_file_finish (_IO_FILE *, int);
79937577 595extern _IO_FILE* _IO_new_file_fopen (_IO_FILE *, const char *, const char *,
0fca3153 596 int);
79937577
UD
597extern void _IO_no_init (_IO_FILE *, int, int, struct _IO_wide_data *,
598 const struct _IO_jump_t *) __THROW;
599extern void _IO_new_file_init (struct _IO_FILE_plus *) __THROW;
0fca3153
UD
600extern _IO_FILE* _IO_new_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
601extern _IO_FILE* _IO_file_setbuf_mmap (_IO_FILE *, char *, _IO_ssize_t);
602extern int _IO_new_file_sync (_IO_FILE *);
603extern int _IO_new_file_underflow (_IO_FILE *);
604extern int _IO_new_file_overflow (_IO_FILE *, int);
605extern _IO_off64_t _IO_new_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
606extern _IO_ssize_t _IO_new_file_write (_IO_FILE *, const void *, _IO_ssize_t);
607extern _IO_size_t _IO_new_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
608
609extern _IO_FILE* _IO_old_file_setbuf (_IO_FILE *, char *, _IO_ssize_t);
610extern _IO_off64_t _IO_old_file_seekoff (_IO_FILE *, _IO_off64_t, int, int);
611extern _IO_size_t _IO_old_file_xsputn (_IO_FILE *, const void *, _IO_size_t);
612extern int _IO_old_file_underflow (_IO_FILE *);
613extern int _IO_old_file_overflow (_IO_FILE *, int);
79937577 614extern void _IO_old_file_init (struct _IO_FILE_plus *) __THROW;
0fca3153
UD
615extern _IO_FILE* _IO_old_file_attach (_IO_FILE *, int);
616extern _IO_FILE* _IO_old_file_fopen (_IO_FILE *, const char *, const char *);
617extern _IO_ssize_t _IO_old_file_write (_IO_FILE *, const void *, _IO_ssize_t);
618extern int _IO_old_file_sync (_IO_FILE *);
619extern int _IO_old_file_close_it (_IO_FILE *);
620extern void _IO_old_file_finish (_IO_FILE *, int);
79937577
UD
621
622extern int _IO_wfile_doallocate (_IO_FILE *) __THROW;
0fca3153 623extern _IO_size_t _IO_wfile_xsputn (_IO_FILE *, const void *, _IO_size_t);
d18ea0c5 624libc_hidden_proto (_IO_wfile_xsputn)
0fca3153
UD
625extern _IO_FILE* _IO_wfile_setbuf (_IO_FILE *, wchar_t *, _IO_ssize_t);
626extern wint_t _IO_wfile_sync (_IO_FILE *);
d18ea0c5 627libc_hidden_proto (_IO_wfile_sync)
0fca3153 628extern wint_t _IO_wfile_underflow (_IO_FILE *);
d18ea0c5 629libc_hidden_proto (_IO_wfile_underflow)
0fca3153 630extern wint_t _IO_wfile_overflow (_IO_FILE *, wint_t);
d18ea0c5 631libc_hidden_proto (_IO_wfile_overflow)
0fca3153 632extern _IO_off64_t _IO_wfile_seekoff (_IO_FILE *, _IO_off64_t, int, int);
d18ea0c5 633libc_hidden_proto (_IO_wfile_seekoff)
d64b6ad0 634
96aa2d94 635/* Jumptable functions for proc_files. */
79937577
UD
636extern _IO_FILE* _IO_proc_open (_IO_FILE *, const char *, const char *)
637 __THROW;
638extern _IO_FILE* _IO_new_proc_open (_IO_FILE *, const char *, const char *)
639 __THROW;
0fca3153 640extern _IO_FILE* _IO_old_proc_open (_IO_FILE *, const char *, const char *);
79937577
UD
641extern int _IO_proc_close (_IO_FILE *) __THROW;
642extern int _IO_new_proc_close (_IO_FILE *) __THROW;
0fca3153 643extern int _IO_old_proc_close (_IO_FILE *);
96aa2d94
RM
644
645/* Jumptable functions for strfiles. */
79937577 646extern int _IO_str_underflow (_IO_FILE *) __THROW;
d18ea0c5 647libc_hidden_proto (_IO_str_underflow)
79937577 648extern int _IO_str_overflow (_IO_FILE *, int) __THROW;
d18ea0c5 649libc_hidden_proto (_IO_str_overflow)
79937577 650extern int _IO_str_pbackfail (_IO_FILE *, int) __THROW;
d18ea0c5 651libc_hidden_proto (_IO_str_pbackfail)
79937577 652extern _IO_off64_t _IO_str_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
d18ea0c5 653libc_hidden_proto (_IO_str_seekoff)
79937577 654extern void _IO_str_finish (_IO_FILE *, int) __THROW;
96aa2d94
RM
655
656/* Other strfile functions */
2ca8b1ee 657struct _IO_strfile_;
79937577
UD
658extern void _IO_str_init_static (struct _IO_strfile_ *, char *, int, char *)
659 __THROW;
660extern void _IO_str_init_readonly (struct _IO_strfile_ *, const char *, int)
661 __THROW;
662extern _IO_ssize_t _IO_str_count (_IO_FILE *) __THROW;
96aa2d94 663
d64b6ad0 664/* And the wide character versions. */
79937577
UD
665extern void _IO_wstr_init_static (_IO_FILE *, wchar_t *, _IO_size_t, wchar_t *)
666 __THROW;
667extern _IO_ssize_t _IO_wstr_count (_IO_FILE *) __THROW;
668extern _IO_wint_t _IO_wstr_overflow (_IO_FILE *, _IO_wint_t) __THROW;
669extern _IO_wint_t _IO_wstr_underflow (_IO_FILE *) __THROW;
670extern _IO_off64_t _IO_wstr_seekoff (_IO_FILE *, _IO_off64_t, int, int)
671 __THROW;
672extern _IO_wint_t _IO_wstr_pbackfail (_IO_FILE *, _IO_wint_t) __THROW;
673extern void _IO_wstr_finish (_IO_FILE *, int) __THROW;
674
a784e502 675extern int _IO_vasprintf (char **result_ptr, const char *format,
79937577 676 _IO_va_list args) __THROW;
a784e502 677extern int _IO_vdprintf (int d, const char *format, _IO_va_list arg);
79937577 678extern int _IO_vsnprintf (char *string, _IO_size_t maxlen,
a784e502 679 const char *format, _IO_va_list args) __THROW;
79937577
UD
680
681
102070bc 682extern _IO_size_t _IO_getline (_IO_FILE *,char *, _IO_size_t, int, int);
d18ea0c5 683libc_hidden_proto (_IO_getline)
79937577 684extern _IO_size_t _IO_getline_info (_IO_FILE *,char *, _IO_size_t,
102070bc 685 int, int, int *);
d18ea0c5 686libc_hidden_proto (_IO_getline_info)
0fca3153 687extern _IO_ssize_t _IO_getdelim (char **, _IO_size_t *, int, _IO_FILE *);
102070bc 688extern _IO_size_t _IO_getwline (_IO_FILE *,wchar_t *, _IO_size_t, wint_t, int);
79937577 689extern _IO_size_t _IO_getwline_info (_IO_FILE *,wchar_t *, _IO_size_t,
102070bc 690 wint_t, int, wint_t *);
96aa2d94 691
2ca8b1ee 692extern struct _IO_FILE_plus *_IO_list_all;
d18ea0c5 693libc_hidden_proto (_IO_list_all)
79937577 694extern void (*_IO_cleanup_registration_needed) (void);
96aa2d94 695
79937577
UD
696extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
697 _IO_size_t, char *) __THROW;
52a16e58 698extern _IO_off64_t _IO_seekoff_unlocked (_IO_FILE *, _IO_off64_t, int, int)
0fca3153 699 attribute_hidden;
52a16e58 700extern _IO_off64_t _IO_seekpos_unlocked (_IO_FILE *, _IO_off64_t, int)
0fca3153 701 attribute_hidden;
77fe0b9c 702
96aa2d94 703#ifndef EOF
40a55d20 704# define EOF (-1)
96aa2d94
RM
705#endif
706#ifndef NULL
40a55d20 707# if defined __GNUG__ && \
f8b87ef0 708 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
40a55d20
UD
709# define NULL (__null)
710# else
711# if !defined(__cplusplus)
712# define NULL ((void*)0)
713# else
714# define NULL (0)
715# endif
716# endif
f65fd747 717#endif
96aa2d94 718
f8b87ef0
UD
719#if _G_HAVE_MMAP
720
40a55d20
UD
721# include <unistd.h>
722# include <fcntl.h>
723# include <sys/mman.h>
724# include <sys/param.h>
f8b87ef0 725
40a55d20
UD
726# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
727# define MAP_ANONYMOUS MAP_ANON
728# endif
f8b87ef0 729
40a55d20
UD
730# if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
731# undef _G_HAVE_MMAP
732# define _G_HAVE_MMAP 0
733# endif
f8b87ef0
UD
734
735#endif /* _G_HAVE_MMAP */
736
737#if _G_HAVE_MMAP
738
40a55d20 739# ifdef _LIBC
10dc2a90 740/* When using this code in the GNU libc we must not pollute the name space. */
40a55d20
UD
741# define mmap __mmap
742# define munmap __munmap
dfd2257a 743# define ftruncate __ftruncate
40a55d20 744# endif
10dc2a90 745
40a55d20 746# define ROUND_TO_PAGE(_S) \
f8b87ef0
UD
747 (((_S) + EXEC_PAGESIZE - 1) & ~(EXEC_PAGESIZE - 1))
748
40a55d20 749# define FREE_BUF(_B, _S) \
f8b87ef0 750 munmap ((_B), ROUND_TO_PAGE (_S))
40a55d20 751# define ALLOC_BUF(_B, _S, _R) \
f8b87ef0
UD
752 do { \
753 (_B) = (char *) mmap (0, ROUND_TO_PAGE (_S), \
754 PROT_READ | PROT_WRITE, \
755 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
d64b6ad0
UD
756 if ((_B) == (char *) MAP_FAILED) \
757 return (_R); \
758 } while (0)
759# define ALLOC_WBUF(_B, _S, _R) \
760 do { \
761 (_B) = (wchar_t *) mmap (0, ROUND_TO_PAGE (_S), \
762 PROT_READ | PROT_WRITE, \
763 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); \
764 if ((_B) == (wchar_t *) MAP_FAILED) \
f8b87ef0
UD
765 return (_R); \
766 } while (0)
767
768#else /* _G_HAVE_MMAP */
769
40a55d20 770# define FREE_BUF(_B, _S) \
f8b87ef0 771 free(_B)
40a55d20 772# define ALLOC_BUF(_B, _S, _R) \
f8b87ef0
UD
773 do { \
774 (_B) = (char*)malloc(_S); \
775 if ((_B) == NULL) \
776 return (_R); \
777 } while (0)
af507979
UD
778# define ALLOC_WBUF(_B, _S, _R) \
779 do { \
780 (_B) = (wchar_t *)malloc(_S); \
781 if ((_B) == NULL) \
782 return (_R); \
783 } while (0)
f8b87ef0
UD
784
785#endif /* _G_HAVE_MMAP */
96aa2d94
RM
786
787#ifndef OS_FSTAT
40a55d20 788# define OS_FSTAT fstat
96aa2d94 789#endif
79937577 790extern int _IO_vscanf (const char *, _IO_va_list) __THROW;
96aa2d94 791
d64b6ad0 792/* _IO_pos_BAD is an _IO_off64_t value indicating error, unknown, or EOF. */
96aa2d94 793#ifndef _IO_pos_BAD
d64b6ad0 794# define _IO_pos_BAD ((_IO_off64_t) -1)
96aa2d94 795#endif
d64b6ad0 796/* _IO_pos_adjust adjust an _IO_off64_t by some number of bytes. */
96aa2d94 797#ifndef _IO_pos_adjust
d64b6ad0 798# define _IO_pos_adjust(pos, delta) ((pos) += (delta))
96aa2d94 799#endif
d64b6ad0 800/* _IO_pos_0 is an _IO_off64_t value indicating beginning of file. */
96aa2d94 801#ifndef _IO_pos_0
d64b6ad0 802# define _IO_pos_0 ((_IO_off64_t) 0)
96aa2d94
RM
803#endif
804
4547c1a4
UD
805#ifdef __cplusplus
806}
807#endif
96aa2d94 808
499e7464 809#ifdef _IO_MTSAFE_IO
96aa2d94 810/* check following! */
1ddf537f 811# ifdef _IO_USE_OLD_IO_FILE
d64b6ad0 812# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
96aa2d94 813 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
319d719d 814 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
73c115ed 815 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
1ddf537f 816# else
319d719d
UD
817# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
818# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
1ddf537f 819 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
319d719d 820 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
d64b6ad0
UD
821 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
822 NULL, WDP, 0 }
319d719d
UD
823# else
824# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
825 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
826 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
827 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
828 0 }
829# endif
1ddf537f 830# endif
499e7464 831#else
1ddf537f 832# ifdef _IO_USE_OLD_IO_FILE
b4e3df5d 833# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
499e7464 834 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
73c115ed
GM
835 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
836 0, _IO_pos_BAD }
1ddf537f 837# else
319d719d
UD
838# if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
839# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
1ddf537f 840 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
319d719d 841 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
d64b6ad0
UD
842 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
843 NULL, WDP, 0 }
319d719d
UD
844# else
845# define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
846 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
847 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (_IO_FILE *) CHAIN, FD, \
848 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
849 0 }
850# endif
1ddf537f 851# endif
499e7464 852#endif
96aa2d94 853
965a54a4 854#define _IO_va_start(args, last) va_start(args, last)
96aa2d94
RM
855
856extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
857
858#if 1
40a55d20 859# define COERCE_FILE(FILE) /* Nothing */
96aa2d94
RM
860#else
861/* This is part of the kludge for binary compatibility with old stdio. */
40a55d20 862# define COERCE_FILE(FILE) \
96aa2d94
RM
863 (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
864 && (FILE) = *(FILE**)&((int*)fp)[1])
865#endif
866
867#ifdef EINVAL
40a55d20 868# define MAYBE_SET_EINVAL __set_errno (EINVAL)
96aa2d94 869#else
40a55d20 870# define MAYBE_SET_EINVAL /* nothing */
96aa2d94
RM
871#endif
872
f65fd747 873#ifdef IO_DEBUG
40a55d20 874# define CHECK_FILE(FILE, RET) \
96aa2d94
RM
875 if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
876 else { COERCE_FILE(FILE); \
877 if (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
68dbb3a6 878 { MAYBE_SET_EINVAL; return RET; }}
96aa2d94 879#else
40a55d20 880# define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
96aa2d94 881#endif
eef80cf8
UD
882
883static inline void
884__attribute__ ((__always_inline__))
885_IO_acquire_lock_fct (_IO_FILE **p)
886{
887 _IO_FILE *fp = *p;
888 if ((fp->_flags & _IO_USER_LOCK) == 0)
889 _IO_funlockfile (fp);
890}
b257c726
UD
891
892static inline void
893__attribute__ ((__always_inline__))
894_IO_acquire_lock_clear_flags2_fct (_IO_FILE **p)
895{
896 _IO_FILE *fp = *p;
874aa523 897 fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD);
b257c726
UD
898 if ((fp->_flags & _IO_USER_LOCK) == 0)
899 _IO_funlockfile (fp);
900}
b2e1c562
RM
901
902#if !defined _IO_MTSAFE_IO && !defined NOT_IN_libc
903# define _IO_acquire_lock(_fp) \
904 do { \
905 _IO_FILE *_IO_acquire_lock_file = NULL
906# define _IO_acquire_lock_clear_flags2(_fp) \
907 do { \
908 _IO_FILE *_IO_acquire_lock_file = (_fp)
909# define _IO_release_lock(_fp) \
910 if (_IO_acquire_lock_file != NULL) \
911 _IO_acquire_lock_file->_flags2 &= ~(_IO_FLAGS2_FORTIFY \
912 | _IO_FLAGS2_SCANF_STD); \
913 } while (0)
914#endif