Fix -Os ferror_unlocked linknamespace, localplt issues (bug 15105, bug 19463).
[glibc.git] / libio / libio.h
blob095312024722a90170046cacd59af66eb1fda3c9
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. */
28 #ifndef _LIBIO_H
29 #define _LIBIO_H 1
31 #ifndef _LIBC
32 # error "libio.h should only be included when building glibc itself"
33 #endif
34 #ifdef _ISOMAC
35 # error "libio.h should not be included under _ISOMAC"
36 #endif
38 #include <stdio.h>
40 #if defined _IO_MTSAFE_IO && !defined _IO_lock_t_defined
41 # error "Someone forgot to include stdio-lock.h"
42 #endif
44 #define __need_wchar_t
45 #include <stddef.h>
47 #include <bits/types/__mbstate_t.h>
48 #include <bits/types/wint_t.h>
49 #include <gconv.h>
51 typedef union
53 struct __gconv_info __cd;
54 struct
56 struct __gconv_info __cd;
57 struct __gconv_step_data __data;
58 } __combined;
59 } _IO_iconv_t;
61 /* Map the names used in libio to the names used in libc generally. */
62 #define _IO_fpos_t __fpos_t
63 #define _IO_fpos64_t __fpos64_t
64 #define _IO_size_t size_t
65 #define _IO_ssize_t __ssize_t
66 #define _IO_off_t __off_t
67 #define _IO_off64_t __off64_t
68 #define _IO_pid_t __pid_t
69 #define _IO_uid_t __uid_t
70 #define _IO_BUFSIZ BUFSIZ
71 #define _IO_wint_t wint_t
72 #define _IO_va_list __gnuc_va_list
74 #include <shlib-compat.h>
76 __BEGIN_DECLS
78 /* compatibility defines */
79 #define _STDIO_USES_IOSTREAM
80 #define _IO_UNIFIED_JUMPTABLES 1
81 #define __HAVE_COLUMN
82 #define _IO_file_flags _flags
84 /* open modes */
85 #define _IOS_INPUT 1
86 #define _IOS_OUTPUT 2
87 #define _IOS_ATEND 4
88 #define _IOS_APPEND 8
89 #define _IOS_TRUNC 16
90 #define _IOS_NOCREATE 32
91 #define _IOS_NOREPLACE 64
92 #define _IOS_BIN 128
94 /* Magic numbers and bits for the _flags field.
95 The magic numbers use the high-order bits of _flags;
96 the remaining bits are available for variable flags.
97 Note: The magic numbers must all be negative if stdio
98 emulation is desired. */
100 #define _IO_MAGIC 0xFBAD0000 /* Magic number */
101 #define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
102 #define _IO_MAGIC_MASK 0xFFFF0000
103 #define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */
104 #define _IO_UNBUFFERED 2
105 #define _IO_NO_READS 4 /* Reading not allowed */
106 #define _IO_NO_WRITES 8 /* Writing not allowd */
107 #define _IO_EOF_SEEN 0x10
108 #define _IO_ERR_SEEN 0x20
109 #define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */
110 #define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/
111 #define _IO_IN_BACKUP 0x100
112 #define _IO_LINE_BUF 0x200
113 #define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */
114 #define _IO_CURRENTLY_PUTTING 0x800
115 #define _IO_IS_APPENDING 0x1000
116 #define _IO_IS_FILEBUF 0x2000
117 #define _IO_BAD_SEEN 0x4000
118 #define _IO_USER_LOCK 0x8000
120 #define _IO_FLAGS2_MMAP 1
121 #define _IO_FLAGS2_NOTCANCEL 2
122 #ifdef _LIBC
123 # define _IO_FLAGS2_FORTIFY 4
124 #endif
125 #define _IO_FLAGS2_USER_WBUF 8
126 #ifdef _LIBC
127 # define _IO_FLAGS2_SCANF_STD 16
128 # define _IO_FLAGS2_NOCLOSE 32
129 # define _IO_FLAGS2_CLOEXEC 64
130 # define _IO_FLAGS2_NEED_LOCK 128
131 #endif
133 /* These are "formatting flags" matching the iostream fmtflags enum values. */
134 #define _IO_SKIPWS 01
135 #define _IO_LEFT 02
136 #define _IO_RIGHT 04
137 #define _IO_INTERNAL 010
138 #define _IO_DEC 020
139 #define _IO_OCT 040
140 #define _IO_HEX 0100
141 #define _IO_SHOWBASE 0200
142 #define _IO_SHOWPOINT 0400
143 #define _IO_UPPERCASE 01000
144 #define _IO_SHOWPOS 02000
145 #define _IO_SCIENTIFIC 04000
146 #define _IO_FIXED 010000
147 #define _IO_UNITBUF 020000
148 #define _IO_STDIO 040000
149 #define _IO_DONT_CLOSE 0100000
150 #define _IO_BOOLALPHA 0200000
153 struct _IO_jump_t;
155 /* A streammarker remembers a position in a buffer. */
157 struct _IO_marker {
158 struct _IO_marker *_next;
159 struct _IO_FILE *_sbuf;
160 /* If _pos >= 0
161 it points to _buf->Gbase()+_pos. FIXME comment */
162 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
163 int _pos;
166 /* This is the structure from the libstdc++ codecvt class. */
167 enum __codecvt_result
169 __codecvt_ok,
170 __codecvt_partial,
171 __codecvt_error,
172 __codecvt_noconv
175 /* The order of the elements in the following struct must match the order
176 of the virtual functions in the libstdc++ codecvt class. */
177 struct _IO_codecvt
179 void (*__codecvt_destr) (struct _IO_codecvt *);
180 enum __codecvt_result (*__codecvt_do_out) (struct _IO_codecvt *,
181 __mbstate_t *,
182 const wchar_t *,
183 const wchar_t *,
184 const wchar_t **, char *,
185 char *, char **);
186 enum __codecvt_result (*__codecvt_do_unshift) (struct _IO_codecvt *,
187 __mbstate_t *, char *,
188 char *, char **);
189 enum __codecvt_result (*__codecvt_do_in) (struct _IO_codecvt *,
190 __mbstate_t *,
191 const char *, const char *,
192 const char **, wchar_t *,
193 wchar_t *, wchar_t **);
194 int (*__codecvt_do_encoding) (struct _IO_codecvt *);
195 int (*__codecvt_do_always_noconv) (struct _IO_codecvt *);
196 int (*__codecvt_do_length) (struct _IO_codecvt *, __mbstate_t *,
197 const char *, const char *, _IO_size_t);
198 int (*__codecvt_do_max_length) (struct _IO_codecvt *);
200 _IO_iconv_t __cd_in;
201 _IO_iconv_t __cd_out;
204 /* Extra data for wide character streams. */
205 struct _IO_wide_data
207 wchar_t *_IO_read_ptr; /* Current read pointer */
208 wchar_t *_IO_read_end; /* End of get area. */
209 wchar_t *_IO_read_base; /* Start of putback+get area. */
210 wchar_t *_IO_write_base; /* Start of put area. */
211 wchar_t *_IO_write_ptr; /* Current put pointer. */
212 wchar_t *_IO_write_end; /* End of put area. */
213 wchar_t *_IO_buf_base; /* Start of reserve area. */
214 wchar_t *_IO_buf_end; /* End of reserve area. */
215 /* The following fields are used to support backing up and undo. */
216 wchar_t *_IO_save_base; /* Pointer to start of non-current get area. */
217 wchar_t *_IO_backup_base; /* Pointer to first valid character of
218 backup area */
219 wchar_t *_IO_save_end; /* Pointer to end of non-current get area. */
221 __mbstate_t _IO_state;
222 __mbstate_t _IO_last_state;
223 struct _IO_codecvt _codecvt;
225 wchar_t _shortbuf[1];
227 const struct _IO_jump_t *_wide_vtable;
231 #ifndef __cplusplus
232 typedef struct _IO_FILE _IO_FILE;
233 #endif
235 struct _IO_FILE_plus;
237 extern struct _IO_FILE_plus _IO_2_1_stdin_;
238 extern struct _IO_FILE_plus _IO_2_1_stdout_;
239 extern struct _IO_FILE_plus _IO_2_1_stderr_;
240 #ifndef _LIBC
241 #define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))
242 #define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
243 #define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
244 #else
245 extern _IO_FILE *_IO_stdin attribute_hidden;
246 extern _IO_FILE *_IO_stdout attribute_hidden;
247 extern _IO_FILE *_IO_stderr attribute_hidden;
248 #endif
251 /* Compatibility names for cookie I/O functions. */
252 #ifdef __USE_GNU
253 typedef cookie_read_function_t __io_read_fn;
254 typedef cookie_write_function_t __io_write_fn;
255 typedef cookie_seek_function_t __io_seek_fn;
256 typedef cookie_close_function_t __io_close_fn;
257 typedef cookie_io_functions_t _IO_cookie_io_functions_t;
259 struct _IO_cookie_file;
261 /* Initialize one of those. */
262 extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write,
263 void *__cookie, _IO_cookie_io_functions_t __fns);
264 #endif
266 extern int __underflow (_IO_FILE *);
267 extern _IO_wint_t __wunderflow (_IO_FILE *);
268 extern _IO_wint_t __wuflow (_IO_FILE *);
269 extern _IO_wint_t __woverflow (_IO_FILE *, _IO_wint_t);
271 #if __GNUC__ >= 3
272 # define _IO_BE(expr, res) __builtin_expect ((expr), res)
273 #else
274 # define _IO_BE(expr, res) (expr)
275 #endif
277 #define _IO_getc_unlocked(_fp) __getc_unlocked_body (_fp)
278 #define _IO_peekc_unlocked(_fp) \
279 (_IO_BE ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end, 0) \
280 && __underflow (_fp) == EOF ? EOF \
281 : *(unsigned char *) (_fp)->_IO_read_ptr)
282 #define _IO_putc_unlocked(_ch, _fp) __putc_unlocked_body (_ch, _fp)
284 # define _IO_getwc_unlocked(_fp) \
285 (_IO_BE ((_fp)->_wide_data == NULL \
286 || ((_fp)->_wide_data->_IO_read_ptr \
287 >= (_fp)->_wide_data->_IO_read_end), 0) \
288 ? __wuflow (_fp) : (_IO_wint_t) *(_fp)->_wide_data->_IO_read_ptr++)
289 # define _IO_putwc_unlocked(_wch, _fp) \
290 (_IO_BE ((_fp)->_wide_data == NULL \
291 || ((_fp)->_wide_data->_IO_write_ptr \
292 >= (_fp)->_wide_data->_IO_write_end), 0) \
293 ? __woverflow (_fp, _wch) \
294 : (_IO_wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch)))
296 #define _IO_feof_unlocked(_fp) __feof_unlocked_body (_fp)
297 #define _IO_ferror_unlocked(_fp) __ferror_unlocked_body (_fp)
299 extern int _IO_getc (_IO_FILE *__fp);
300 extern int _IO_putc (int __c, _IO_FILE *__fp);
301 extern int _IO_feof (_IO_FILE *__fp) __THROW;
302 extern int _IO_ferror (_IO_FILE *__fp) __THROW;
304 extern int _IO_peekc_locked (_IO_FILE *__fp);
306 /* This one is for Emacs. */
307 #define _IO_PENDING_OUTPUT_COUNT(_fp) \
308 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
310 extern void _IO_flockfile (_IO_FILE *) __THROW;
311 extern void _IO_funlockfile (_IO_FILE *) __THROW;
312 extern int _IO_ftrylockfile (_IO_FILE *) __THROW;
314 #define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
315 #define _IO_flockfile(_fp) /**/
316 #define _IO_funlockfile(_fp) /**/
317 #define _IO_ftrylockfile(_fp) /**/
318 #ifndef _IO_cleanup_region_start
319 #define _IO_cleanup_region_start(_fct, _fp) /**/
320 #endif
321 #ifndef _IO_cleanup_region_end
322 #define _IO_cleanup_region_end(_Doit) /**/
323 #endif
325 #define _IO_need_lock(_fp) \
326 (((_fp)->_flags2 & _IO_FLAGS2_NEED_LOCK) != 0)
328 extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
329 _IO_va_list, int *__restrict);
330 extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
331 _IO_va_list);
332 extern _IO_ssize_t _IO_padn (_IO_FILE *, int, _IO_ssize_t);
333 extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t);
335 extern _IO_off64_t _IO_seekoff (_IO_FILE *, _IO_off64_t, int, int);
336 extern _IO_off64_t _IO_seekpos (_IO_FILE *, _IO_off64_t, int);
338 extern void _IO_free_backup_area (_IO_FILE *) __THROW;
341 extern _IO_wint_t _IO_getwc (_IO_FILE *__fp);
342 extern _IO_wint_t _IO_putwc (wchar_t __wc, _IO_FILE *__fp);
343 extern int _IO_fwide (_IO_FILE *__fp, int __mode) __THROW;
345 /* While compiling glibc we have to handle compatibility with very old
346 versions. */
347 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
348 # define _IO_fwide_maybe_incompatible \
349 (__builtin_expect (&_IO_stdin_used == NULL, 0))
350 extern const int _IO_stdin_used;
351 weak_extern (_IO_stdin_used);
352 #else
353 # define _IO_fwide_maybe_incompatible (0)
354 #endif
356 /* A special optimized version of the function above. It optimizes the
357 case of initializing an unoriented byte stream. */
358 #define _IO_fwide(__fp, __mode) \
359 ({ int __result = (__mode); \
360 if (__result < 0 && ! _IO_fwide_maybe_incompatible) \
362 if ((__fp)->_mode == 0) \
363 /* We know that all we have to do is to set the flag. */ \
364 (__fp)->_mode = -1; \
365 __result = (__fp)->_mode; \
367 else if (__builtin_constant_p (__mode) && (__mode) == 0) \
368 __result = _IO_fwide_maybe_incompatible ? -1 : (__fp)->_mode; \
369 else \
370 __result = _IO_fwide (__fp, __result); \
371 __result; })
373 extern int _IO_vfwscanf (_IO_FILE * __restrict, const wchar_t * __restrict,
374 _IO_va_list, int *__restrict);
375 extern int _IO_vfwprintf (_IO_FILE *__restrict, const wchar_t *__restrict,
376 _IO_va_list);
377 extern _IO_ssize_t _IO_wpadn (_IO_FILE *, wint_t, _IO_ssize_t);
378 extern void _IO_free_wbackup_area (_IO_FILE *) __THROW;
380 #ifdef __LDBL_COMPAT
381 __LDBL_REDIR_DECL (_IO_vfscanf)
382 __LDBL_REDIR_DECL (_IO_vfprintf)
383 #endif
385 libc_hidden_proto (__overflow)
386 libc_hidden_proto (__underflow)
387 libc_hidden_proto (__uflow)
388 libc_hidden_proto (__woverflow)
389 libc_hidden_proto (__wunderflow)
390 libc_hidden_proto (__wuflow)
391 libc_hidden_proto (_IO_free_backup_area)
392 libc_hidden_proto (_IO_free_wbackup_area)
393 libc_hidden_proto (_IO_padn)
394 libc_hidden_proto (_IO_putc)
395 libc_hidden_proto (_IO_sgetn)
396 libc_hidden_proto (_IO_vfprintf)
397 libc_hidden_proto (_IO_vfscanf)
399 #ifdef _IO_MTSAFE_IO
400 # undef _IO_peekc
401 # undef _IO_flockfile
402 # undef _IO_funlockfile
403 # undef _IO_ftrylockfile
405 # define _IO_peekc(_fp) _IO_peekc_locked (_fp)
406 # if _IO_lock_inexpensive
407 # define _IO_flockfile(_fp) \
408 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_lock (*(_fp)->_lock)
409 # define _IO_funlockfile(_fp) \
410 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_unlock (*(_fp)->_lock)
411 # else
412 # define _IO_flockfile(_fp) \
413 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_flockfile (_fp)
414 # define _IO_funlockfile(_fp) \
415 if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_funlockfile (_fp)
416 # endif
417 #endif /* _IO_MTSAFE_IO */
419 __END_DECLS
421 #endif /* _LIBIO_H */