]> git.ipfire.org Git - thirdparty/glibc.git/blob - libio/libioP.h
Add __vfscanf_internal and __vfwscanf_internal with flags arguments.
[thirdparty/glibc.git] / libio / libioP.h
1 /* Copyright (C) 1993-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>.
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. */
26
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
35 #ifndef _LIBIOP_H
36 #define _LIBIOP_H 1
37
38 #include <stddef.h>
39
40 #include <errno.h>
41 #include <libc-lock.h>
42
43 #include <math_ldbl_opt.h>
44
45 #include <stdio.h>
46 #include <libio/libio.h>
47 #include "iolibio.h"
48
49 #include <shlib-compat.h>
50
51 /* For historical reasons this is the name of the sysdeps header that
52 adjusts the libio configuration. */
53 #include <_G_config.h>
54
55 #define _IO_seek_set 0
56 #define _IO_seek_cur 1
57 #define _IO_seek_end 2
58
59 /* THE JUMPTABLE FUNCTIONS.
60
61 * The _IO_FILE type is used to implement the FILE type in GNU libc,
62 * as well as the streambuf class in GNU iostreams for C++.
63 * These are all the same, just used differently.
64 * An _IO_FILE (or FILE) object is allows followed by a pointer to
65 * a jump table (of pointers to functions). The pointer is accessed
66 * with the _IO_JUMPS macro. The jump table has an eccentric format,
67 * so as to be compatible with the layout of a C++ virtual function table.
68 * (as implemented by g++). When a pointer to a streambuf object is
69 * coerced to an (FILE*), then _IO_JUMPS on the result just
70 * happens to point to the virtual function table of the streambuf.
71 * Thus the _IO_JUMPS function table used for C stdio/libio does
72 * double duty as the virtual function table for C++ streambuf.
73 *
74 * The entries in the _IO_JUMPS function table (and hence also the
75 * virtual functions of a streambuf) are described below.
76 * The first parameter of each function entry is the _IO_FILE/streambuf
77 * object being acted on (i.e. the 'this' parameter).
78 */
79
80 /* Setting this macro to 1 enables the use of the _vtable_offset bias
81 in _IO_JUMPS_FUNCS, below. This is only needed for new-format
82 _IO_FILE in libc that must support old binaries (see oldfileops.c). */
83 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) && !defined _IO_USE_OLD_IO_FILE
84 # define _IO_JUMPS_OFFSET 1
85 #else
86 # define _IO_JUMPS_OFFSET 0
87 #endif
88
89 /* Type of MEMBER in struct type TYPE. */
90 #define _IO_MEMBER_TYPE(TYPE, MEMBER) __typeof__ (((TYPE){}).MEMBER)
91
92 /* Essentially ((TYPE *) THIS)->MEMBER, but avoiding the aliasing
93 violation in case THIS has a different pointer type. */
94 #define _IO_CAST_FIELD_ACCESS(THIS, TYPE, MEMBER) \
95 (*(_IO_MEMBER_TYPE (TYPE, MEMBER) *)(((char *) (THIS)) \
96 + offsetof(TYPE, MEMBER)))
97
98 #define _IO_JUMPS(THIS) (THIS)->vtable
99 #define _IO_JUMPS_FILE_plus(THIS) \
100 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE_plus, vtable)
101 #define _IO_WIDE_JUMPS(THIS) \
102 _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data)->_wide_vtable
103 #define _IO_CHECK_WIDE(THIS) \
104 (_IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data) != NULL)
105
106 #if _IO_JUMPS_OFFSET
107 # define _IO_JUMPS_FUNC(THIS) \
108 (IO_validate_vtable \
109 (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
110 + (THIS)->_vtable_offset)))
111 # define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
112 #else
113 # define _IO_JUMPS_FUNC(THIS) (IO_validate_vtable (_IO_JUMPS_FILE_plus (THIS)))
114 # define _IO_vtable_offset(THIS) 0
115 #endif
116 #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
117 #define JUMP_FIELD(TYPE, NAME) TYPE NAME
118 #define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
119 #define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
120 #define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
121 #define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
122 #define JUMP_INIT(NAME, VALUE) VALUE
123 #define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
124
125 #define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
126 #define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
127 #define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
128 #define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
129
130 /* The 'finish' function does any final cleaning up of an _IO_FILE object.
131 It does not delete (free) it, but does everything else to finalize it.
132 It matches the streambuf::~streambuf virtual destructor. */
133 typedef void (*_IO_finish_t) (FILE *, int); /* finalize */
134 #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
135 #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
136
137 /* The 'overflow' hook flushes the buffer.
138 The second argument is a character, or EOF.
139 It matches the streambuf::overflow virtual function. */
140 typedef int (*_IO_overflow_t) (FILE *, int);
141 #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
142 #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
143
144 /* The 'underflow' hook tries to fills the get buffer.
145 It returns the next character (as an unsigned char) or EOF. The next
146 character remains in the get buffer, and the get position is not changed.
147 It matches the streambuf::underflow virtual function. */
148 typedef int (*_IO_underflow_t) (FILE *);
149 #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
150 #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
151
152 /* The 'uflow' hook returns the next character in the input stream
153 (cast to unsigned char), and increments the read position;
154 EOF is returned on failure.
155 It matches the streambuf::uflow virtual function, which is not in the
156 cfront implementation, but was added to C++ by the ANSI/ISO committee. */
157 #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
158 #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
159
160 /* The 'pbackfail' hook handles backing up.
161 It matches the streambuf::pbackfail virtual function. */
162 typedef int (*_IO_pbackfail_t) (FILE *, int);
163 #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
164 #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
165
166 /* The 'xsputn' hook writes upto N characters from buffer DATA.
167 Returns EOF or the number of character actually written.
168 It matches the streambuf::xsputn virtual function. */
169 typedef size_t (*_IO_xsputn_t) (FILE *FP, const void *DATA,
170 size_t N);
171 #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
172 #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
173
174 /* The 'xsgetn' hook reads upto N characters into buffer DATA.
175 Returns the number of character actually read.
176 It matches the streambuf::xsgetn virtual function. */
177 typedef size_t (*_IO_xsgetn_t) (FILE *FP, void *DATA, size_t N);
178 #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
179 #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
180
181 /* The 'seekoff' hook moves the stream position to a new position
182 relative to the start of the file (if DIR==0), the current position
183 (MODE==1), or the end of the file (MODE==2).
184 It matches the streambuf::seekoff virtual function.
185 It is also used for the ANSI fseek function. */
186 typedef off64_t (*_IO_seekoff_t) (FILE *FP, off64_t OFF, int DIR,
187 int MODE);
188 #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
189 #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
190
191 /* The 'seekpos' hook also moves the stream position,
192 but to an absolute position given by a fpos64_t (seekpos).
193 It matches the streambuf::seekpos virtual function.
194 It is also used for the ANSI fgetpos and fsetpos functions. */
195 /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
196 typedef off64_t (*_IO_seekpos_t) (FILE *, off64_t, int);
197 #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
198 #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
199
200 /* The 'setbuf' hook gives a buffer to the file.
201 It matches the streambuf::setbuf virtual function. */
202 typedef FILE* (*_IO_setbuf_t) (FILE *, char *, ssize_t);
203 #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
204 #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
205
206 /* The 'sync' hook attempts to synchronize the internal data structures
207 of the file with the external state.
208 It matches the streambuf::sync virtual function. */
209 typedef int (*_IO_sync_t) (FILE *);
210 #define _IO_SYNC(FP) JUMP0 (__sync, FP)
211 #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
212
213 /* The 'doallocate' hook is used to tell the file to allocate a buffer.
214 It matches the streambuf::doallocate virtual function, which is not
215 in the ANSI/ISO C++ standard, but is part traditional implementations. */
216 typedef int (*_IO_doallocate_t) (FILE *);
217 #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
218 #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
219
220 /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
221 sysstat) are low-level hooks specific to this implementation.
222 There is no correspondence in the ANSI/ISO C++ standard library.
223 The hooks basically correspond to the Unix system functions
224 (read, write, close, lseek, and stat) except that a FILE*
225 parameter is used instead of an integer file descriptor; the default
226 implementation used for normal files just calls those functions.
227 The advantage of overriding these functions instead of the higher-level
228 ones (underflow, overflow etc) is that you can leave all the buffering
229 higher-level functions. */
230
231 /* The 'sysread' hook is used to read data from the external file into
232 an existing buffer. It generalizes the Unix read(2) function.
233 It matches the streambuf::sys_read virtual function, which is
234 specific to this implementation. */
235 typedef ssize_t (*_IO_read_t) (FILE *, void *, ssize_t);
236 #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
237 #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
238
239 /* The 'syswrite' hook is used to write data from an existing buffer
240 to an external file. It generalizes the Unix write(2) function.
241 It matches the streambuf::sys_write virtual function, which is
242 specific to this implementation. */
243 typedef ssize_t (*_IO_write_t) (FILE *, const void *, ssize_t);
244 #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
245 #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
246
247 /* The 'sysseek' hook is used to re-position an external file.
248 It generalizes the Unix lseek(2) function.
249 It matches the streambuf::sys_seek virtual function, which is
250 specific to this implementation. */
251 typedef off64_t (*_IO_seek_t) (FILE *, off64_t, int);
252 #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
253 #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
254
255 /* The 'sysclose' hook is used to finalize (close, finish up) an
256 external file. It generalizes the Unix close(2) function.
257 It matches the streambuf::sys_close virtual function, which is
258 specific to this implementation. */
259 typedef int (*_IO_close_t) (FILE *); /* finalize */
260 #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
261 #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
262
263 /* The 'sysstat' hook is used to get information about an external file
264 into a struct stat buffer. It generalizes the Unix fstat(2) call.
265 It matches the streambuf::sys_stat virtual function, which is
266 specific to this implementation. */
267 typedef int (*_IO_stat_t) (FILE *, void *);
268 #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
269 #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
270
271 /* The 'showmany' hook can be used to get an image how much input is
272 available. In many cases the answer will be 0 which means unknown
273 but some cases one can provide real information. */
274 typedef int (*_IO_showmanyc_t) (FILE *);
275 #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
276 #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
277
278 /* The 'imbue' hook is used to get information about the currently
279 installed locales. */
280 typedef void (*_IO_imbue_t) (FILE *, void *);
281 #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
282 #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
283
284
285 #define _IO_CHAR_TYPE char /* unsigned char ? */
286 #define _IO_INT_TYPE int
287
288 struct _IO_jump_t
289 {
290 JUMP_FIELD(size_t, __dummy);
291 JUMP_FIELD(size_t, __dummy2);
292 JUMP_FIELD(_IO_finish_t, __finish);
293 JUMP_FIELD(_IO_overflow_t, __overflow);
294 JUMP_FIELD(_IO_underflow_t, __underflow);
295 JUMP_FIELD(_IO_underflow_t, __uflow);
296 JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
297 /* showmany */
298 JUMP_FIELD(_IO_xsputn_t, __xsputn);
299 JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
300 JUMP_FIELD(_IO_seekoff_t, __seekoff);
301 JUMP_FIELD(_IO_seekpos_t, __seekpos);
302 JUMP_FIELD(_IO_setbuf_t, __setbuf);
303 JUMP_FIELD(_IO_sync_t, __sync);
304 JUMP_FIELD(_IO_doallocate_t, __doallocate);
305 JUMP_FIELD(_IO_read_t, __read);
306 JUMP_FIELD(_IO_write_t, __write);
307 JUMP_FIELD(_IO_seek_t, __seek);
308 JUMP_FIELD(_IO_close_t, __close);
309 JUMP_FIELD(_IO_stat_t, __stat);
310 JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
311 JUMP_FIELD(_IO_imbue_t, __imbue);
312 };
313
314 /* We always allocate an extra word following an _IO_FILE.
315 This contains a pointer to the function jump table used.
316 This is for compatibility with C++ streambuf; the word can
317 be used to smash to a pointer to a virtual function table. */
318
319 struct _IO_FILE_plus
320 {
321 FILE file;
322 const struct _IO_jump_t *vtable;
323 };
324
325 #ifdef _IO_USE_OLD_IO_FILE
326 /* This structure is used by the compatibility code as if it were an
327 _IO_FILE_plus, but has enough space to initialize the _mode argument
328 of an _IO_FILE_complete. */
329 struct _IO_FILE_complete_plus
330 {
331 struct _IO_FILE_complete file;
332 const struct _IO_jump_t *vtable;
333 };
334 #endif
335
336 /* Special file type for fopencookie function. */
337 struct _IO_cookie_file
338 {
339 struct _IO_FILE_plus __fp;
340 void *__cookie;
341 cookie_io_functions_t __io_functions;
342 };
343
344 FILE *_IO_fopencookie (void *cookie, const char *mode,
345 cookie_io_functions_t io_functions);
346
347
348 /* Iterator type for walking global linked list of _IO_FILE objects. */
349
350 typedef FILE *_IO_ITER;
351
352 /* Generic functions */
353
354 extern void _IO_switch_to_main_get_area (FILE *) __THROW;
355 extern void _IO_switch_to_backup_area (FILE *) __THROW;
356 extern int _IO_switch_to_get_mode (FILE *);
357 libc_hidden_proto (_IO_switch_to_get_mode)
358 extern void _IO_init_internal (FILE *, int) attribute_hidden;
359 extern int _IO_sputbackc (FILE *, int) __THROW;
360 libc_hidden_proto (_IO_sputbackc)
361 extern int _IO_sungetc (FILE *) __THROW;
362 extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
363 libc_hidden_proto (_IO_un_link)
364 extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
365 libc_hidden_proto (_IO_link_in)
366 extern void _IO_doallocbuf (FILE *) __THROW;
367 libc_hidden_proto (_IO_doallocbuf)
368 extern void _IO_unsave_markers (FILE *) __THROW;
369 libc_hidden_proto (_IO_unsave_markers)
370 extern void _IO_setb (FILE *, char *, char *, int) __THROW;
371 libc_hidden_proto (_IO_setb)
372 extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
373 libc_hidden_proto (_IO_adjust_column)
374 #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
375
376 ssize_t _IO_least_wmarker (FILE *, wchar_t *) __THROW;
377 libc_hidden_proto (_IO_least_wmarker)
378 extern void _IO_switch_to_main_wget_area (FILE *) __THROW;
379 libc_hidden_proto (_IO_switch_to_main_wget_area)
380 extern void _IO_switch_to_wbackup_area (FILE *) __THROW;
381 libc_hidden_proto (_IO_switch_to_wbackup_area)
382 extern int _IO_switch_to_wget_mode (FILE *);
383 libc_hidden_proto (_IO_switch_to_wget_mode)
384 extern void _IO_wsetb (FILE *, wchar_t *, wchar_t *, int) __THROW;
385 libc_hidden_proto (_IO_wsetb)
386 extern wint_t _IO_sputbackwc (FILE *, wint_t) __THROW;
387 libc_hidden_proto (_IO_sputbackwc)
388 extern wint_t _IO_sungetwc (FILE *) __THROW;
389 extern void _IO_wdoallocbuf (FILE *) __THROW;
390 libc_hidden_proto (_IO_wdoallocbuf)
391 extern void _IO_unsave_wmarkers (FILE *) __THROW;
392 extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
393 extern off64_t get_file_offset (FILE *fp);
394
395 /* Marker-related function. */
396
397 extern void _IO_init_marker (struct _IO_marker *, FILE *);
398 extern void _IO_init_wmarker (struct _IO_marker *, FILE *);
399 extern void _IO_remove_marker (struct _IO_marker *) __THROW;
400 extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
401 __THROW;
402 extern int _IO_marker_delta (struct _IO_marker *) __THROW;
403 extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
404 extern int _IO_seekmark (FILE *, struct _IO_marker *, int) __THROW;
405 extern int _IO_seekwmark (FILE *, struct _IO_marker *, int) __THROW;
406
407 /* Functions for iterating global list and dealing with its lock */
408
409 extern _IO_ITER _IO_iter_begin (void) __THROW;
410 libc_hidden_proto (_IO_iter_begin)
411 extern _IO_ITER _IO_iter_end (void) __THROW;
412 libc_hidden_proto (_IO_iter_end)
413 extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
414 libc_hidden_proto (_IO_iter_next)
415 extern FILE *_IO_iter_file (_IO_ITER) __THROW;
416 libc_hidden_proto (_IO_iter_file)
417 extern void _IO_list_lock (void) __THROW;
418 libc_hidden_proto (_IO_list_lock)
419 extern void _IO_list_unlock (void) __THROW;
420 libc_hidden_proto (_IO_list_unlock)
421 extern void _IO_list_resetlock (void) __THROW;
422 libc_hidden_proto (_IO_list_resetlock)
423 extern void _IO_enable_locks (void) __THROW;
424 libc_hidden_proto (_IO_enable_locks)
425
426 /* Default jumptable functions. */
427
428 extern int _IO_default_underflow (FILE *) __THROW;
429 extern int _IO_default_uflow (FILE *);
430 libc_hidden_proto (_IO_default_uflow)
431 extern wint_t _IO_wdefault_uflow (FILE *);
432 libc_hidden_proto (_IO_wdefault_uflow)
433 extern int _IO_default_doallocate (FILE *) __THROW;
434 libc_hidden_proto (_IO_default_doallocate)
435 extern int _IO_wdefault_doallocate (FILE *) __THROW;
436 libc_hidden_proto (_IO_wdefault_doallocate)
437 extern void _IO_default_finish (FILE *, int) __THROW;
438 libc_hidden_proto (_IO_default_finish)
439 extern void _IO_wdefault_finish (FILE *, int) __THROW;
440 libc_hidden_proto (_IO_wdefault_finish)
441 extern int _IO_default_pbackfail (FILE *, int) __THROW;
442 libc_hidden_proto (_IO_default_pbackfail)
443 extern wint_t _IO_wdefault_pbackfail (FILE *, wint_t) __THROW;
444 libc_hidden_proto (_IO_wdefault_pbackfail)
445 extern FILE* _IO_default_setbuf (FILE *, char *, ssize_t);
446 extern size_t _IO_default_xsputn (FILE *, const void *, size_t);
447 libc_hidden_proto (_IO_default_xsputn)
448 extern size_t _IO_wdefault_xsputn (FILE *, const void *, size_t);
449 libc_hidden_proto (_IO_wdefault_xsputn)
450 extern size_t _IO_default_xsgetn (FILE *, void *, size_t);
451 libc_hidden_proto (_IO_default_xsgetn)
452 extern size_t _IO_wdefault_xsgetn (FILE *, void *, size_t);
453 libc_hidden_proto (_IO_wdefault_xsgetn)
454 extern off64_t _IO_default_seekoff (FILE *, off64_t, int, int)
455 __THROW;
456 extern off64_t _IO_default_seekpos (FILE *, off64_t, int);
457 extern ssize_t _IO_default_write (FILE *, const void *, ssize_t);
458 extern ssize_t _IO_default_read (FILE *, void *, ssize_t);
459 extern int _IO_default_stat (FILE *, void *) __THROW;
460 extern off64_t _IO_default_seek (FILE *, off64_t, int) __THROW;
461 extern int _IO_default_sync (FILE *) __THROW;
462 #define _IO_default_close ((_IO_close_t) _IO_default_sync)
463 extern int _IO_default_showmanyc (FILE *) __THROW;
464 extern void _IO_default_imbue (FILE *, void *) __THROW;
465
466 extern const struct _IO_jump_t _IO_file_jumps;
467 libc_hidden_proto (_IO_file_jumps)
468 extern const struct _IO_jump_t _IO_file_jumps_mmap attribute_hidden;
469 extern const struct _IO_jump_t _IO_file_jumps_maybe_mmap attribute_hidden;
470 extern const struct _IO_jump_t _IO_wfile_jumps;
471 libc_hidden_proto (_IO_wfile_jumps)
472 extern const struct _IO_jump_t _IO_wfile_jumps_mmap attribute_hidden;
473 extern const struct _IO_jump_t _IO_wfile_jumps_maybe_mmap attribute_hidden;
474 extern const struct _IO_jump_t _IO_old_file_jumps attribute_hidden;
475 extern const struct _IO_jump_t _IO_streambuf_jumps;
476 extern const struct _IO_jump_t _IO_old_proc_jumps attribute_hidden;
477 extern const struct _IO_jump_t _IO_str_jumps attribute_hidden;
478 extern const struct _IO_jump_t _IO_wstr_jumps attribute_hidden;
479 extern const struct _IO_codecvt __libio_codecvt attribute_hidden;
480 extern int _IO_do_write (FILE *, const char *, size_t);
481 libc_hidden_proto (_IO_do_write)
482 extern int _IO_new_do_write (FILE *, const char *, size_t);
483 extern int _IO_old_do_write (FILE *, const char *, size_t);
484 extern int _IO_wdo_write (FILE *, const wchar_t *, size_t);
485 libc_hidden_proto (_IO_wdo_write)
486 extern int _IO_flush_all_lockp (int);
487 extern int _IO_flush_all (void);
488 libc_hidden_proto (_IO_flush_all)
489 extern int _IO_cleanup (void);
490 extern void _IO_flush_all_linebuffered (void);
491 libc_hidden_proto (_IO_flush_all_linebuffered)
492 extern int _IO_new_fgetpos (FILE *, __fpos_t *);
493 extern int _IO_old_fgetpos (FILE *, __fpos_t *);
494 extern int _IO_new_fsetpos (FILE *, const __fpos_t *);
495 extern int _IO_old_fsetpos (FILE *, const __fpos_t *);
496 extern int _IO_new_fgetpos64 (FILE *, __fpos64_t *);
497 extern int _IO_old_fgetpos64 (FILE *, __fpos64_t *);
498 extern int _IO_new_fsetpos64 (FILE *, const __fpos64_t *);
499 extern int _IO_old_fsetpos64 (FILE *, const __fpos64_t *);
500 extern void _IO_old_init (FILE *fp, int flags) __THROW;
501
502
503 #define _IO_do_flush(_f) \
504 ((_f)->_mode <= 0 \
505 ? _IO_do_write(_f, (_f)->_IO_write_base, \
506 (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
507 : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
508 ((_f)->_wide_data->_IO_write_ptr \
509 - (_f)->_wide_data->_IO_write_base)))
510 #define _IO_old_do_flush(_f) \
511 _IO_old_do_write(_f, (_f)->_IO_write_base, \
512 (_f)->_IO_write_ptr-(_f)->_IO_write_base)
513 #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
514 #define _IO_mask_flags(fp, f, mask) \
515 ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
516 #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
517 (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
518 #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
519 (fp)->_wide_data->_IO_read_ptr = (g), \
520 (fp)->_wide_data->_IO_read_end = (eg))
521 #define _IO_setp(__fp, __p, __ep) \
522 ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
523 = __p, (__fp)->_IO_write_end = (__ep))
524 #define _IO_wsetp(__fp, __p, __ep) \
525 ((__fp)->_wide_data->_IO_write_base \
526 = (__fp)->_wide_data->_IO_write_ptr = __p, \
527 (__fp)->_wide_data->_IO_write_end = (__ep))
528 #define _IO_have_backup(fp) ((fp)->_IO_save_base != NULL)
529 #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_save_base != NULL)
530 #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
531 #define _IO_have_markers(fp) ((fp)->_markers != NULL)
532 #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
533 #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
534 - (fp)->_wide_data->_IO_buf_base)
535
536 /* Jumptable functions for files. */
537
538 extern int _IO_file_doallocate (FILE *) __THROW;
539 libc_hidden_proto (_IO_file_doallocate)
540 extern FILE* _IO_file_setbuf (FILE *, char *, ssize_t);
541 libc_hidden_proto (_IO_file_setbuf)
542 extern off64_t _IO_file_seekoff (FILE *, off64_t, int, int);
543 libc_hidden_proto (_IO_file_seekoff)
544 extern off64_t _IO_file_seekoff_mmap (FILE *, off64_t, int, int)
545 __THROW;
546 extern size_t _IO_file_xsputn (FILE *, const void *, size_t);
547 libc_hidden_proto (_IO_file_xsputn)
548 extern size_t _IO_file_xsgetn (FILE *, void *, size_t);
549 libc_hidden_proto (_IO_file_xsgetn)
550 extern int _IO_file_stat (FILE *, void *) __THROW;
551 libc_hidden_proto (_IO_file_stat)
552 extern int _IO_file_close (FILE *) __THROW;
553 libc_hidden_proto (_IO_file_close)
554 extern int _IO_file_close_mmap (FILE *) __THROW;
555 extern int _IO_file_underflow (FILE *);
556 libc_hidden_proto (_IO_file_underflow)
557 extern int _IO_file_underflow_mmap (FILE *);
558 extern int _IO_file_underflow_maybe_mmap (FILE *);
559 extern int _IO_file_overflow (FILE *, int);
560 libc_hidden_proto (_IO_file_overflow)
561 #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
562 extern FILE* _IO_file_attach (FILE *, int);
563 libc_hidden_proto (_IO_file_attach)
564 extern FILE* _IO_file_open (FILE *, const char *, int, int, int, int);
565 libc_hidden_proto (_IO_file_open)
566 extern FILE* _IO_file_fopen (FILE *, const char *, const char *, int);
567 libc_hidden_proto (_IO_file_fopen)
568 extern ssize_t _IO_file_write (FILE *, const void *, ssize_t);
569 extern ssize_t _IO_file_read (FILE *, void *, ssize_t);
570 libc_hidden_proto (_IO_file_read)
571 extern int _IO_file_sync (FILE *);
572 libc_hidden_proto (_IO_file_sync)
573 extern int _IO_file_close_it (FILE *);
574 libc_hidden_proto (_IO_file_close_it)
575 extern off64_t _IO_file_seek (FILE *, off64_t, int) __THROW;
576 libc_hidden_proto (_IO_file_seek)
577 extern void _IO_file_finish (FILE *, int);
578 libc_hidden_proto (_IO_file_finish)
579
580 extern FILE* _IO_new_file_attach (FILE *, int);
581 extern int _IO_new_file_close_it (FILE *);
582 extern void _IO_new_file_finish (FILE *, int);
583 extern FILE* _IO_new_file_fopen (FILE *, const char *, const char *,
584 int);
585 extern void _IO_no_init (FILE *, int, int, struct _IO_wide_data *,
586 const struct _IO_jump_t *) __THROW;
587 extern void _IO_new_file_init_internal (struct _IO_FILE_plus *)
588 __THROW attribute_hidden;
589 extern FILE* _IO_new_file_setbuf (FILE *, char *, ssize_t);
590 extern FILE* _IO_file_setbuf_mmap (FILE *, char *, ssize_t);
591 extern int _IO_new_file_sync (FILE *);
592 extern int _IO_new_file_underflow (FILE *);
593 extern int _IO_new_file_overflow (FILE *, int);
594 extern off64_t _IO_new_file_seekoff (FILE *, off64_t, int, int);
595 extern ssize_t _IO_new_file_write (FILE *, const void *, ssize_t);
596 extern size_t _IO_new_file_xsputn (FILE *, const void *, size_t);
597
598 extern FILE* _IO_old_file_setbuf (FILE *, char *, ssize_t);
599 extern off64_t _IO_old_file_seekoff (FILE *, off64_t, int, int);
600 extern size_t _IO_old_file_xsputn (FILE *, const void *, size_t);
601 extern int _IO_old_file_underflow (FILE *);
602 extern int _IO_old_file_overflow (FILE *, int);
603 extern void _IO_old_file_init_internal (struct _IO_FILE_plus *)
604 __THROW attribute_hidden;
605 extern FILE* _IO_old_file_attach (FILE *, int);
606 extern FILE* _IO_old_file_fopen (FILE *, const char *, const char *);
607 extern ssize_t _IO_old_file_write (FILE *, const void *, ssize_t);
608 extern int _IO_old_file_sync (FILE *);
609 extern int _IO_old_file_close_it (FILE *);
610 extern void _IO_old_file_finish (FILE *, int);
611
612 extern int _IO_wfile_doallocate (FILE *) __THROW;
613 extern size_t _IO_wfile_xsputn (FILE *, const void *, size_t);
614 libc_hidden_proto (_IO_wfile_xsputn)
615 extern FILE* _IO_wfile_setbuf (FILE *, wchar_t *, ssize_t);
616 extern wint_t _IO_wfile_sync (FILE *);
617 libc_hidden_proto (_IO_wfile_sync)
618 extern wint_t _IO_wfile_underflow (FILE *);
619 libc_hidden_proto (_IO_wfile_underflow)
620 extern wint_t _IO_wfile_overflow (FILE *, wint_t);
621 libc_hidden_proto (_IO_wfile_overflow)
622 extern off64_t _IO_wfile_seekoff (FILE *, off64_t, int, int);
623 libc_hidden_proto (_IO_wfile_seekoff)
624
625 /* Jumptable functions for proc_files. */
626 extern FILE* _IO_proc_open (FILE *, const char *, const char *)
627 __THROW;
628 extern FILE* _IO_new_proc_open (FILE *, const char *, const char *)
629 __THROW;
630 extern FILE* _IO_old_proc_open (FILE *, const char *, const char *);
631 extern int _IO_proc_close (FILE *) __THROW;
632 extern int _IO_new_proc_close (FILE *) __THROW;
633 extern int _IO_old_proc_close (FILE *);
634
635 /* Jumptable functions for strfiles. */
636 extern int _IO_str_underflow (FILE *) __THROW;
637 libc_hidden_proto (_IO_str_underflow)
638 extern int _IO_str_overflow (FILE *, int) __THROW;
639 libc_hidden_proto (_IO_str_overflow)
640 extern int _IO_str_pbackfail (FILE *, int) __THROW;
641 libc_hidden_proto (_IO_str_pbackfail)
642 extern off64_t _IO_str_seekoff (FILE *, off64_t, int, int) __THROW;
643 libc_hidden_proto (_IO_str_seekoff)
644 extern void _IO_str_finish (FILE *, int) __THROW;
645
646 /* Other strfile functions */
647 struct _IO_strfile_;
648 extern ssize_t _IO_str_count (FILE *) __THROW;
649
650 /* And the wide character versions. */
651 extern void _IO_wstr_init_static (FILE *, wchar_t *, size_t, wchar_t *)
652 __THROW;
653 extern ssize_t _IO_wstr_count (FILE *) __THROW;
654 extern wint_t _IO_wstr_overflow (FILE *, wint_t) __THROW;
655 extern wint_t _IO_wstr_underflow (FILE *) __THROW;
656 extern off64_t _IO_wstr_seekoff (FILE *, off64_t, int, int)
657 __THROW;
658 extern wint_t _IO_wstr_pbackfail (FILE *, wint_t) __THROW;
659 extern void _IO_wstr_finish (FILE *, int) __THROW;
660
661 extern int _IO_vasprintf (char **result_ptr, const char *format,
662 va_list args) __THROW;
663 extern int _IO_vdprintf (int d, const char *format, va_list arg);
664 extern int _IO_vsnprintf (char *string, size_t maxlen,
665 const char *format, va_list args) __THROW;
666
667
668 extern size_t _IO_getline (FILE *,char *, size_t, int, int);
669 libc_hidden_proto (_IO_getline)
670 extern size_t _IO_getline_info (FILE *,char *, size_t,
671 int, int, int *);
672 libc_hidden_proto (_IO_getline_info)
673 extern ssize_t _IO_getdelim (char **, size_t *, int, FILE *);
674 extern size_t _IO_getwline (FILE *,wchar_t *, size_t, wint_t, int);
675 extern size_t _IO_getwline_info (FILE *,wchar_t *, size_t,
676 wint_t, int, wint_t *);
677
678 extern struct _IO_FILE_plus *_IO_list_all;
679 libc_hidden_proto (_IO_list_all)
680 extern void (*_IO_cleanup_registration_needed) (void);
681
682 extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
683 size_t, char *) __THROW;
684 extern off64_t _IO_seekoff_unlocked (FILE *, off64_t, int, int)
685 attribute_hidden;
686 extern off64_t _IO_seekpos_unlocked (FILE *, off64_t, int)
687 attribute_hidden;
688
689 #if _G_HAVE_MMAP
690
691 # include <unistd.h>
692 # include <fcntl.h>
693 # include <sys/mman.h>
694 # include <sys/param.h>
695
696 # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
697 # define MAP_ANONYMOUS MAP_ANON
698 # endif
699
700 # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
701 # undef _G_HAVE_MMAP
702 # define _G_HAVE_MMAP 0
703 # endif
704
705 #endif /* _G_HAVE_MMAP */
706
707 /* Flags for __vfscanf_internal and __vfwscanf_internal.
708
709 SCANF_LDBL_IS_DBL indicates whether long double values are to be
710 handled as having the same format as double, in which case the flag
711 should be set to one, or as another format, otherwise.
712
713 SCANF_ISOC99_A, when set to one, indicates that the ISO C99 or POSIX
714 behavior of the scanf functions is to be used, i.e. automatic
715 allocation for input strings with %as, %aS and %a[, a GNU extension,
716 is disabled. This is the behavior that the __isoc99_scanf family of
717 functions use. When the flag is set to zero, automatic allocation is
718 enabled. */
719 #define SCANF_LDBL_IS_DBL 0x0001
720 #define SCANF_ISOC99_A 0x0002
721
722 extern int __vfscanf_internal (FILE *fp, const char *format, va_list argp,
723 unsigned int flags)
724 attribute_hidden;
725 extern int __vfwscanf_internal (FILE *fp, const wchar_t *format, va_list argp,
726 unsigned int flags)
727 attribute_hidden;
728
729 extern int _IO_vscanf (const char *, va_list) __THROW;
730
731 #ifdef _IO_MTSAFE_IO
732 /* check following! */
733 # ifdef _IO_USE_OLD_IO_FILE
734 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
735 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
736 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (FILE *) CHAIN, FD, \
737 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
738 # else
739 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
740 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
741 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (FILE *) CHAIN, FD, \
742 0, _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, _IO_pos_BAD,\
743 NULL, WDP, 0 }
744 # endif
745 #else
746 # ifdef _IO_USE_OLD_IO_FILE
747 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
748 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
749 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (FILE *) CHAIN, FD, \
750 0, _IO_pos_BAD }
751 # else
752 # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
753 { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
754 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (FILE *) CHAIN, FD, \
755 0, _IO_pos_BAD, 0, 0, { 0 }, 0, _IO_pos_BAD, \
756 NULL, WDP, 0 }
757 # endif
758 #endif
759
760 extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
761
762 #ifdef IO_DEBUG
763 # define CHECK_FILE(FILE, RET) do { \
764 if ((FILE) == NULL || \
765 ((FILE)->_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
766 { \
767 __set_errno (EINVAL); \
768 return RET; \
769 } \
770 } while (0)
771 #else
772 # define CHECK_FILE(FILE, RET) do { } while (0)
773 #endif
774
775 static inline void
776 __attribute__ ((__always_inline__))
777 _IO_acquire_lock_fct (FILE **p)
778 {
779 FILE *fp = *p;
780 if ((fp->_flags & _IO_USER_LOCK) == 0)
781 _IO_funlockfile (fp);
782 }
783
784 static inline void
785 __attribute__ ((__always_inline__))
786 _IO_acquire_lock_clear_flags2_fct (FILE **p)
787 {
788 FILE *fp = *p;
789 fp->_flags2 &= ~(_IO_FLAGS2_FORTIFY | _IO_FLAGS2_SCANF_STD);
790 if ((fp->_flags & _IO_USER_LOCK) == 0)
791 _IO_funlockfile (fp);
792 }
793
794 #if !defined _IO_MTSAFE_IO && IS_IN (libc)
795 # define _IO_acquire_lock(_fp) \
796 do { \
797 FILE *_IO_acquire_lock_file = NULL
798 # define _IO_acquire_lock_clear_flags2(_fp) \
799 do { \
800 FILE *_IO_acquire_lock_file = (_fp)
801 # define _IO_release_lock(_fp) \
802 if (_IO_acquire_lock_file != NULL) \
803 _IO_acquire_lock_file->_flags2 &= ~(_IO_FLAGS2_FORTIFY \
804 | _IO_FLAGS2_SCANF_STD); \
805 } while (0)
806 #endif
807
808 /* Collect all vtables in a special section for vtable verification.
809 These symbols cover the extent of this section. */
810 symbol_set_declare (__libc_IO_vtables)
811
812 /* libio vtables need to carry this attribute so that they pass
813 validation. */
814 #define libio_vtable __attribute__ ((section ("__libc_IO_vtables")))
815
816 #ifdef SHARED
817 /* If equal to &_IO_vtable_check (with pointer guard protection),
818 unknown vtable pointers are valid. This function pointer is solely
819 used as a flag. */
820 extern void (*IO_accept_foreign_vtables) (void) attribute_hidden;
821
822 /* Assigns the passed function pointer (either NULL or
823 &_IO_vtable_check) to IO_accept_foreign_vtables. */
824 static inline void
825 IO_set_accept_foreign_vtables (void (*flag) (void))
826 {
827 #ifdef PTR_MANGLE
828 PTR_MANGLE (flag);
829 #endif
830 atomic_store_relaxed (&IO_accept_foreign_vtables, flag);
831 }
832
833 #else /* !SHARED */
834
835 /* The statically-linked version does nothing. */
836 static inline void
837 IO_set_accept_foreign_vtables (void (*flag) (void))
838 {
839 }
840
841 #endif
842
843 /* Check if unknown vtable pointers are permitted; otherwise,
844 terminate the process. */
845 void _IO_vtable_check (void) attribute_hidden;
846
847 /* Perform vtable pointer validation. If validation fails, terminate
848 the process. */
849 static inline const struct _IO_jump_t *
850 IO_validate_vtable (const struct _IO_jump_t *vtable)
851 {
852 /* Fast path: The vtable pointer is within the __libc_IO_vtables
853 section. */
854 uintptr_t section_length = __stop___libc_IO_vtables - __start___libc_IO_vtables;
855 uintptr_t ptr = (uintptr_t) vtable;
856 uintptr_t offset = ptr - (uintptr_t) __start___libc_IO_vtables;
857 if (__glibc_unlikely (offset >= section_length))
858 /* The vtable pointer is not in the expected section. Use the
859 slow path, which will terminate the process if necessary. */
860 _IO_vtable_check ();
861 return vtable;
862 }
863
864 #endif /* libioP.h. */