1 /* Copyright (C) 1991-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Per Bothner <bothner@cygnus.com>.
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.
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
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>.
19 As a special exception, if you link the code in this file with
20 files compiled with a GNU compiler to produce an executable,
21 that does not cause the resulting executable to be covered by
22 the GNU Lesser General Public License. This exception does not
23 however invalidate any other reasons why the executable file
24 might be covered by the GNU Lesser General Public License.
25 This exception applies to code released by its copyright holders
26 in files containing the exception. */
32 # error "libio.h should only be included when building glibc itself"
35 # error "libio.h should not be included under _ISOMAC"
40 #if defined _IO_MTSAFE_IO && !defined _IO_lock_t_defined
41 # error "Someone forgot to include stdio-lock.h"
44 #include <bits/_G_config.h>
45 /* ALL of these should be defined in _G_config.h */
46 #define _IO_fpos_t __fpos_t
47 #define _IO_fpos64_t __fpos64_t
48 #define _IO_size_t size_t
49 #define _IO_ssize_t __ssize_t
50 #define _IO_off_t __off_t
51 #define _IO_off64_t __off64_t
52 #define _IO_pid_t __pid_t
53 #define _IO_uid_t __uid_t
54 #define _IO_iconv_t _G_iconv_t
55 #define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
56 #define _IO_BUFSIZ BUFSIZ
57 #define _IO_wint_t wint_t
58 #define _IO_va_list __gnuc_va_list
60 #include <shlib-compat.h>
64 /* compatibility defines */
65 #define _STDIO_USES_IOSTREAM
66 #define _IO_UNIFIED_JUMPTABLES 1
68 #define _IO_file_flags _flags
76 #define _IOS_NOCREATE 32
77 #define _IOS_NOREPLACE 64
80 /* Magic numbers and bits for the _flags field.
81 The magic numbers use the high-order bits of _flags;
82 the remaining bits are available for variable flags.
83 Note: The magic numbers must all be negative if stdio
84 emulation is desired. */
86 #define _IO_MAGIC 0xFBAD0000 /* Magic number */
87 #define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
88 #define _IO_MAGIC_MASK 0xFFFF0000
89 #define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */
90 #define _IO_UNBUFFERED 2
91 #define _IO_NO_READS 4 /* Reading not allowed */
92 #define _IO_NO_WRITES 8 /* Writing not allowd */
93 #define _IO_EOF_SEEN 0x10
94 #define _IO_ERR_SEEN 0x20
95 #define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */
96 #define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/
97 #define _IO_IN_BACKUP 0x100
98 #define _IO_LINE_BUF 0x200
99 #define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */
100 #define _IO_CURRENTLY_PUTTING 0x800
101 #define _IO_IS_APPENDING 0x1000
102 #define _IO_IS_FILEBUF 0x2000
103 #define _IO_BAD_SEEN 0x4000
104 #define _IO_USER_LOCK 0x8000
106 #define _IO_FLAGS2_MMAP 1
107 #define _IO_FLAGS2_NOTCANCEL 2
109 # define _IO_FLAGS2_FORTIFY 4
111 #define _IO_FLAGS2_USER_WBUF 8
113 # define _IO_FLAGS2_SCANF_STD 16
114 # define _IO_FLAGS2_NOCLOSE 32
115 # define _IO_FLAGS2_CLOEXEC 64
116 # define _IO_FLAGS2_NEED_LOCK 128
119 /* These are "formatting flags" matching the iostream fmtflags enum values. */
120 #define _IO_SKIPWS 01
123 #define _IO_INTERNAL 010
127 #define _IO_SHOWBASE 0200
128 #define _IO_SHOWPOINT 0400
129 #define _IO_UPPERCASE 01000
130 #define _IO_SHOWPOS 02000
131 #define _IO_SCIENTIFIC 04000
132 #define _IO_FIXED 010000
133 #define _IO_UNITBUF 020000
134 #define _IO_STDIO 040000
135 #define _IO_DONT_CLOSE 0100000
136 #define _IO_BOOLALPHA 0200000
141 /* A streammarker remembers a position in a buffer. */
144 struct _IO_marker
*_next
;
145 struct _IO_FILE
*_sbuf
;
147 it points to _buf->Gbase()+_pos. FIXME comment */
148 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
152 /* This is the structure from the libstdc++ codecvt class. */
153 enum __codecvt_result
161 /* The order of the elements in the following struct must match the order
162 of the virtual functions in the libstdc++ codecvt class. */
165 void (*__codecvt_destr
) (struct _IO_codecvt
*);
166 enum __codecvt_result (*__codecvt_do_out
) (struct _IO_codecvt
*,
170 const wchar_t **, char *,
172 enum __codecvt_result (*__codecvt_do_unshift
) (struct _IO_codecvt
*,
173 __mbstate_t
*, char *,
175 enum __codecvt_result (*__codecvt_do_in
) (struct _IO_codecvt
*,
177 const char *, const char *,
178 const char **, wchar_t *,
179 wchar_t *, wchar_t **);
180 int (*__codecvt_do_encoding
) (struct _IO_codecvt
*);
181 int (*__codecvt_do_always_noconv
) (struct _IO_codecvt
*);
182 int (*__codecvt_do_length
) (struct _IO_codecvt
*, __mbstate_t
*,
183 const char *, const char *, _IO_size_t
);
184 int (*__codecvt_do_max_length
) (struct _IO_codecvt
*);
187 _IO_iconv_t __cd_out
;
190 /* Extra data for wide character streams. */
193 wchar_t *_IO_read_ptr
; /* Current read pointer */
194 wchar_t *_IO_read_end
; /* End of get area. */
195 wchar_t *_IO_read_base
; /* Start of putback+get area. */
196 wchar_t *_IO_write_base
; /* Start of put area. */
197 wchar_t *_IO_write_ptr
; /* Current put pointer. */
198 wchar_t *_IO_write_end
; /* End of put area. */
199 wchar_t *_IO_buf_base
; /* Start of reserve area. */
200 wchar_t *_IO_buf_end
; /* End of reserve area. */
201 /* The following fields are used to support backing up and undo. */
202 wchar_t *_IO_save_base
; /* Pointer to start of non-current get area. */
203 wchar_t *_IO_backup_base
; /* Pointer to first valid character of
205 wchar_t *_IO_save_end
; /* Pointer to end of non-current get area. */
207 __mbstate_t _IO_state
;
208 __mbstate_t _IO_last_state
;
209 struct _IO_codecvt _codecvt
;
211 wchar_t _shortbuf
[1];
213 const struct _IO_jump_t
*_wide_vtable
;
218 typedef struct _IO_FILE _IO_FILE
;
221 struct _IO_FILE_plus
;
223 extern struct _IO_FILE_plus _IO_2_1_stdin_
;
224 extern struct _IO_FILE_plus _IO_2_1_stdout_
;
225 extern struct _IO_FILE_plus _IO_2_1_stderr_
;
227 #define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))
228 #define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
229 #define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
231 extern _IO_FILE
*_IO_stdin attribute_hidden
;
232 extern _IO_FILE
*_IO_stdout attribute_hidden
;
233 extern _IO_FILE
*_IO_stderr attribute_hidden
;
237 /* Compatibility names for cookie I/O functions. */
239 typedef cookie_read_function_t __io_read_fn
;
240 typedef cookie_write_function_t __io_write_fn
;
241 typedef cookie_seek_function_t __io_seek_fn
;
242 typedef cookie_close_function_t __io_close_fn
;
243 typedef cookie_io_functions_t _IO_cookie_io_functions_t
;
245 struct _IO_cookie_file
;
247 /* Initialize one of those. */
248 extern void _IO_cookie_init (struct _IO_cookie_file
*__cfile
, int __read_write
,
249 void *__cookie
, _IO_cookie_io_functions_t __fns
);
252 extern int __underflow (_IO_FILE
*);
253 extern _IO_wint_t
__wunderflow (_IO_FILE
*);
254 extern _IO_wint_t
__wuflow (_IO_FILE
*);
255 extern _IO_wint_t
__woverflow (_IO_FILE
*, _IO_wint_t
);
258 # define _IO_BE(expr, res) __builtin_expect ((expr), res)
260 # define _IO_BE(expr, res) (expr)
263 #define _IO_getc_unlocked(_fp) __getc_unlocked_body (_fp)
264 #define _IO_peekc_unlocked(_fp) \
265 (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) \
266 && __underflow (_fp) == EOF ? EOF \
267 : *(unsigned char *) (_fp)->_IO_read_ptr)
268 #define _IO_putc_unlocked(_ch, _fp) __putc_unlocked_body (_ch, _fp)
270 # define _IO_getwc_unlocked(_fp) \
271 (_IO_BE ((_fp)->_wide_data == NULL \
272 || ((_fp)->_wide_data->_IO_read_ptr \
273 >= (_fp)->_wide_data->_IO_read_end), 0) \
274 ? __wuflow (_fp) : (_IO_wint_t) *(_fp)->_wide_data->_IO_read_ptr++)
275 # define _IO_putwc_unlocked(_wch, _fp) \
276 (_IO_BE ((_fp)->_wide_data == NULL \
277 || ((_fp)->_wide_data->_IO_write_ptr \
278 >= (_fp)->_wide_data->_IO_write_end), 0) \
279 ? __woverflow (_fp, _wch) \
280 : (_IO_wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch)))
282 #define _IO_feof_unlocked(_fp) __feof_unlocked_body (_fp)
283 #define _IO_ferror_unlocked(_fp) __ferror_unlocked_body (_fp)
285 extern int _IO_getc (_IO_FILE
*__fp
);
286 extern int _IO_putc (int __c
, _IO_FILE
*__fp
);
287 extern int _IO_feof (_IO_FILE
*__fp
) __THROW
;
288 extern int _IO_ferror (_IO_FILE
*__fp
) __THROW
;
290 extern int _IO_peekc_locked (_IO_FILE
*__fp
);
292 /* This one is for Emacs. */
293 #define _IO_PENDING_OUTPUT_COUNT(_fp) \
294 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
296 extern void _IO_flockfile (_IO_FILE
*) __THROW
;
297 extern void _IO_funlockfile (_IO_FILE
*) __THROW
;
298 extern int _IO_ftrylockfile (_IO_FILE
*) __THROW
;
300 #define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
301 #define _IO_flockfile(_fp) /**/
302 #define _IO_funlockfile(_fp) /**/
303 #define _IO_ftrylockfile(_fp) /**/
304 #ifndef _IO_cleanup_region_start
305 #define _IO_cleanup_region_start(_fct, _fp) /**/
307 #ifndef _IO_cleanup_region_end
308 #define _IO_cleanup_region_end(_Doit) /**/
311 #define _IO_need_lock(_fp) \
312 (((_fp)->_flags2 & _IO_FLAGS2_NEED_LOCK) != 0)
314 extern int _IO_vfscanf (_IO_FILE
* __restrict
, const char * __restrict
,
315 _IO_va_list
, int *__restrict
);
316 extern int _IO_vfprintf (_IO_FILE
*__restrict
, const char *__restrict
,
318 extern _IO_ssize_t
_IO_padn (_IO_FILE
*, int, _IO_ssize_t
);
319 extern _IO_size_t
_IO_sgetn (_IO_FILE
*, void *, _IO_size_t
);
321 extern _IO_off64_t
_IO_seekoff (_IO_FILE
*, _IO_off64_t
, int, int);
322 extern _IO_off64_t
_IO_seekpos (_IO_FILE
*, _IO_off64_t
, int);
324 extern void _IO_free_backup_area (_IO_FILE
*) __THROW
;
327 extern _IO_wint_t
_IO_getwc (_IO_FILE
*__fp
);
328 extern _IO_wint_t
_IO_putwc (wchar_t __wc
, _IO_FILE
*__fp
);
329 extern int _IO_fwide (_IO_FILE
*__fp
, int __mode
) __THROW
;
331 /* While compiling glibc we have to handle compatibility with very old
333 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
334 # define _IO_fwide_maybe_incompatible \
335 (__builtin_expect (&_IO_stdin_used == NULL, 0))
336 extern const int _IO_stdin_used
;
337 weak_extern (_IO_stdin_used
);
339 # define _IO_fwide_maybe_incompatible (0)
342 /* A special optimized version of the function above. It optimizes the
343 case of initializing an unoriented byte stream. */
344 #define _IO_fwide(__fp, __mode) \
345 ({ int __result = (__mode); \
346 if (__result < 0 && ! _IO_fwide_maybe_incompatible) \
348 if ((__fp)->_mode == 0) \
349 /* We know that all we have to do is to set the flag. */ \
350 (__fp)->_mode = -1; \
351 __result = (__fp)->_mode; \
353 else if (__builtin_constant_p (__mode) && (__mode) == 0) \
354 __result = _IO_fwide_maybe_incompatible ? -1 : (__fp)->_mode; \
356 __result = _IO_fwide (__fp, __result); \
359 extern int _IO_vfwscanf (_IO_FILE
* __restrict
, const wchar_t * __restrict
,
360 _IO_va_list
, int *__restrict
);
361 extern int _IO_vfwprintf (_IO_FILE
*__restrict
, const wchar_t *__restrict
,
363 extern _IO_ssize_t
_IO_wpadn (_IO_FILE
*, wint_t, _IO_ssize_t
);
364 extern void _IO_free_wbackup_area (_IO_FILE
*) __THROW
;
367 __LDBL_REDIR_DECL (_IO_vfscanf
)
368 __LDBL_REDIR_DECL (_IO_vfprintf
)
371 libc_hidden_proto (__overflow
)
372 libc_hidden_proto (__underflow
)
373 libc_hidden_proto (__uflow
)
374 libc_hidden_proto (__woverflow
)
375 libc_hidden_proto (__wunderflow
)
376 libc_hidden_proto (__wuflow
)
377 libc_hidden_proto (_IO_free_backup_area
)
378 libc_hidden_proto (_IO_free_wbackup_area
)
379 libc_hidden_proto (_IO_padn
)
380 libc_hidden_proto (_IO_putc
)
381 libc_hidden_proto (_IO_sgetn
)
382 libc_hidden_proto (_IO_vfprintf
)
383 libc_hidden_proto (_IO_vfscanf
)
387 # undef _IO_flockfile
388 # undef _IO_funlockfile
389 # undef _IO_ftrylockfile
391 # define _IO_peekc(_fp) _IO_peekc_locked (_fp)
392 # if _IO_lock_inexpensive
393 # define _IO_flockfile(_fp) \
394 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_lock (*(_fp)->_lock)
395 # define _IO_funlockfile(_fp) \
396 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_unlock (*(_fp)->_lock)
398 # define _IO_flockfile(_fp) \
399 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_flockfile (_fp)
400 # define _IO_funlockfile(_fp) \
401 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_funlockfile (_fp)
403 #endif /* _IO_MTSAFE_IO */
407 #endif /* _LIBIO_H */