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