| 1 | /* Copyright (C) 1991-2020 Free Software Foundation, Inc. | 
|---|
| 2 | This file is part of the GNU C Library. | 
|---|
| 3 | Written by Per Bothner <bothner@cygnus.com>. | 
|---|
| 4 |  | 
|---|
| 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. | 
|---|
| 9 |  | 
|---|
| 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. | 
|---|
| 14 |  | 
|---|
| 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 | <https://www.gnu.org/licenses/>. | 
|---|
| 18 |  | 
|---|
| 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.  */ | 
|---|
| 27 |  | 
|---|
| 28 | #ifndef _LIBIO_H | 
|---|
| 29 | #define _LIBIO_H 1 | 
|---|
| 30 |  | 
|---|
| 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 | 
|---|
| 37 |  | 
|---|
| 38 | #include <stdio.h> | 
|---|
| 39 |  | 
|---|
| 40 | #if defined _IO_MTSAFE_IO && !defined _IO_lock_t_defined | 
|---|
| 41 | # error "Someone forgot to include stdio-lock.h" | 
|---|
| 42 | #endif | 
|---|
| 43 |  | 
|---|
| 44 | #define __need_wchar_t | 
|---|
| 45 | #include <stddef.h> | 
|---|
| 46 |  | 
|---|
| 47 | #include <bits/types/__mbstate_t.h> | 
|---|
| 48 | #include <bits/types/wint_t.h> | 
|---|
| 49 | #include <gconv.h> | 
|---|
| 50 |  | 
|---|
| 51 | typedef struct | 
|---|
| 52 | { | 
|---|
| 53 | struct __gconv_step *step; | 
|---|
| 54 | struct __gconv_step_data step_data; | 
|---|
| 55 | } _IO_iconv_t; | 
|---|
| 56 |  | 
|---|
| 57 | #include <shlib-compat.h> | 
|---|
| 58 |  | 
|---|
| 59 | /* _IO_seekoff modes */ | 
|---|
| 60 | #define _IOS_INPUT	1 | 
|---|
| 61 | #define _IOS_OUTPUT	2 | 
|---|
| 62 |  | 
|---|
| 63 | /* Magic number and bits for the _flags field.  The magic number is | 
|---|
| 64 | mostly vestigial, but preserved for compatibility.  It occupies the | 
|---|
| 65 | high 16 bits of _flags; the low 16 bits are actual flag bits.  */ | 
|---|
| 66 |  | 
|---|
| 67 | #define _IO_MAGIC         0xFBAD0000 /* Magic number */ | 
|---|
| 68 | #define _IO_MAGIC_MASK    0xFFFF0000 | 
|---|
| 69 | #define _IO_USER_BUF          0x0001 /* Don't deallocate buffer on close. */ | 
|---|
| 70 | #define _IO_UNBUFFERED        0x0002 | 
|---|
| 71 | #define _IO_NO_READS          0x0004 /* Reading not allowed.  */ | 
|---|
| 72 | #define _IO_NO_WRITES         0x0008 /* Writing not allowed.  */ | 
|---|
| 73 | #define _IO_EOF_SEEN          0x0010 | 
|---|
| 74 | #define _IO_ERR_SEEN          0x0020 | 
|---|
| 75 | #define _IO_DELETE_DONT_CLOSE 0x0040 /* Don't call close(_fileno) on close.  */ | 
|---|
| 76 | #define _IO_LINKED            0x0080 /* In the list of all open files.  */ | 
|---|
| 77 | #define _IO_IN_BACKUP         0x0100 | 
|---|
| 78 | #define _IO_LINE_BUF          0x0200 | 
|---|
| 79 | #define _IO_TIED_PUT_GET      0x0400 /* Put and get pointer move in unison.  */ | 
|---|
| 80 | #define _IO_CURRENTLY_PUTTING 0x0800 | 
|---|
| 81 | #define _IO_IS_APPENDING      0x1000 | 
|---|
| 82 | #define _IO_IS_FILEBUF        0x2000 | 
|---|
| 83 | /* 0x4000  No longer used, reserved for compat.  */ | 
|---|
| 84 | #define _IO_USER_LOCK         0x8000 | 
|---|
| 85 |  | 
|---|
| 86 | /* Bits for the _flags2 field.  */ | 
|---|
| 87 | #define _IO_FLAGS2_MMAP 1 | 
|---|
| 88 | #define _IO_FLAGS2_NOTCANCEL 2 | 
|---|
| 89 | #define _IO_FLAGS2_USER_WBUF 8 | 
|---|
| 90 | #define _IO_FLAGS2_NOCLOSE 32 | 
|---|
| 91 | #define _IO_FLAGS2_CLOEXEC 64 | 
|---|
| 92 | #define _IO_FLAGS2_NEED_LOCK 128 | 
|---|
| 93 |  | 
|---|
| 94 | /* _IO_pos_BAD is an off64_t value indicating error, unknown, or EOF.  */ | 
|---|
| 95 | #define _IO_pos_BAD ((off64_t) -1) | 
|---|
| 96 |  | 
|---|
| 97 | /* _IO_pos_adjust adjusts an off64_t by some number of bytes.  */ | 
|---|
| 98 | #define _IO_pos_adjust(pos, delta) ((pos) += (delta)) | 
|---|
| 99 |  | 
|---|
| 100 | /* _IO_pos_0 is an off64_t value indicating beginning of file.  */ | 
|---|
| 101 | #define _IO_pos_0 ((off64_t) 0) | 
|---|
| 102 |  | 
|---|
| 103 | struct _IO_jump_t; | 
|---|
| 104 |  | 
|---|
| 105 | /* A streammarker remembers a position in a buffer. */ | 
|---|
| 106 | struct _IO_marker { | 
|---|
| 107 | struct _IO_marker *_next; | 
|---|
| 108 | FILE *_sbuf; | 
|---|
| 109 | /* If _pos >= 0 | 
|---|
| 110 | it points to _buf->Gbase()+_pos. FIXME comment */ | 
|---|
| 111 | /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */ | 
|---|
| 112 | int _pos; | 
|---|
| 113 | }; | 
|---|
| 114 |  | 
|---|
| 115 | struct _IO_codecvt | 
|---|
| 116 | { | 
|---|
| 117 | _IO_iconv_t __cd_in; | 
|---|
| 118 | _IO_iconv_t __cd_out; | 
|---|
| 119 | }; | 
|---|
| 120 |  | 
|---|
| 121 | /* Extra data for wide character streams.  */ | 
|---|
| 122 | struct _IO_wide_data | 
|---|
| 123 | { | 
|---|
| 124 | wchar_t *_IO_read_ptr;	/* Current read pointer */ | 
|---|
| 125 | wchar_t *_IO_read_end;	/* End of get area. */ | 
|---|
| 126 | wchar_t *_IO_read_base;	/* Start of putback+get area. */ | 
|---|
| 127 | wchar_t *_IO_write_base;	/* Start of put area. */ | 
|---|
| 128 | wchar_t *_IO_write_ptr;	/* Current put pointer. */ | 
|---|
| 129 | wchar_t *_IO_write_end;	/* End of put area. */ | 
|---|
| 130 | wchar_t *_IO_buf_base;	/* Start of reserve area. */ | 
|---|
| 131 | wchar_t *_IO_buf_end;		/* End of reserve area. */ | 
|---|
| 132 | /* The following fields are used to support backing up and undo. */ | 
|---|
| 133 | wchar_t *_IO_save_base;	/* Pointer to start of non-current get area. */ | 
|---|
| 134 | wchar_t *_IO_backup_base;	/* Pointer to first valid character of | 
|---|
| 135 | backup area */ | 
|---|
| 136 | wchar_t *_IO_save_end;	/* Pointer to end of non-current get area. */ | 
|---|
| 137 |  | 
|---|
| 138 | __mbstate_t _IO_state; | 
|---|
| 139 | __mbstate_t _IO_last_state; | 
|---|
| 140 | struct _IO_codecvt _codecvt; | 
|---|
| 141 |  | 
|---|
| 142 | wchar_t _shortbuf[1]; | 
|---|
| 143 |  | 
|---|
| 144 | const struct _IO_jump_t *_wide_vtable; | 
|---|
| 145 | }; | 
|---|
| 146 |  | 
|---|
| 147 | struct _IO_FILE_plus; | 
|---|
| 148 |  | 
|---|
| 149 | extern struct _IO_FILE_plus _IO_2_1_stdin_; | 
|---|
| 150 | extern struct _IO_FILE_plus _IO_2_1_stdout_; | 
|---|
| 151 | extern struct _IO_FILE_plus _IO_2_1_stderr_; | 
|---|
| 152 |  | 
|---|
| 153 | struct _IO_cookie_file; | 
|---|
| 154 |  | 
|---|
| 155 | /* Initialize one of those.  */ | 
|---|
| 156 | extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write, | 
|---|
| 157 | void *__cookie, cookie_io_functions_t __fns); | 
|---|
| 158 |  | 
|---|
| 159 | extern int __underflow (FILE *); | 
|---|
| 160 | extern wint_t __wunderflow (FILE *); | 
|---|
| 161 | extern wint_t __wuflow (FILE *); | 
|---|
| 162 | extern wint_t __woverflow (FILE *, wint_t); | 
|---|
| 163 |  | 
|---|
| 164 | #define _IO_getc_unlocked(_fp) __getc_unlocked_body (_fp) | 
|---|
| 165 | #define _IO_peekc_unlocked(_fp)						\ | 
|---|
| 166 | (__glibc_unlikely ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end)	\ | 
|---|
| 167 | && __underflow (_fp) == EOF						\ | 
|---|
| 168 | ? EOF								\ | 
|---|
| 169 | : *(unsigned char *) (_fp)->_IO_read_ptr) | 
|---|
| 170 | #define _IO_putc_unlocked(_ch, _fp) __putc_unlocked_body (_ch, _fp) | 
|---|
| 171 |  | 
|---|
| 172 | # define _IO_getwc_unlocked(_fp)					\ | 
|---|
| 173 | (__glibc_unlikely ((_fp)->_wide_data == NULL				\ | 
|---|
| 174 | || ((_fp)->_wide_data->_IO_read_ptr		\ | 
|---|
| 175 | >= (_fp)->_wide_data->_IO_read_end))		\ | 
|---|
| 176 | ? __wuflow (_fp) : (wint_t) *(_fp)->_wide_data->_IO_read_ptr++) | 
|---|
| 177 | # define _IO_putwc_unlocked(_wch, _fp)					\ | 
|---|
| 178 | (__glibc_unlikely ((_fp)->_wide_data == NULL				\ | 
|---|
| 179 | || ((_fp)->_wide_data->_IO_write_ptr		\ | 
|---|
| 180 | >= (_fp)->_wide_data->_IO_write_end))		\ | 
|---|
| 181 | ? __woverflow (_fp, _wch)						\ | 
|---|
| 182 | : (wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch))) | 
|---|
| 183 |  | 
|---|
| 184 | #define _IO_feof_unlocked(_fp) __feof_unlocked_body (_fp) | 
|---|
| 185 | #define _IO_ferror_unlocked(_fp) __ferror_unlocked_body (_fp) | 
|---|
| 186 |  | 
|---|
| 187 | extern int _IO_getc (FILE *__fp); | 
|---|
| 188 | extern int _IO_putc (int __c, FILE *__fp); | 
|---|
| 189 | extern int _IO_feof (FILE *__fp) __THROW; | 
|---|
| 190 | extern int _IO_ferror (FILE *__fp) __THROW; | 
|---|
| 191 |  | 
|---|
| 192 | extern int _IO_peekc_locked (FILE *__fp); | 
|---|
| 193 |  | 
|---|
| 194 | /* This one is for Emacs. */ | 
|---|
| 195 | #define _IO_PENDING_OUTPUT_COUNT(_fp)	\ | 
|---|
| 196 | ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base) | 
|---|
| 197 |  | 
|---|
| 198 | extern void _IO_flockfile (FILE *) __THROW; | 
|---|
| 199 | extern void _IO_funlockfile (FILE *) __THROW; | 
|---|
| 200 | extern int _IO_ftrylockfile (FILE *) __THROW; | 
|---|
| 201 |  | 
|---|
| 202 | #define _IO_peekc(_fp) _IO_peekc_unlocked (_fp) | 
|---|
| 203 | #define _IO_flockfile(_fp) /**/ | 
|---|
| 204 | #define _IO_funlockfile(_fp) ((void) 0) | 
|---|
| 205 | #define _IO_ftrylockfile(_fp) /**/ | 
|---|
| 206 | #ifndef _IO_cleanup_region_start | 
|---|
| 207 | #define _IO_cleanup_region_start(_fct, _fp) /**/ | 
|---|
| 208 | #endif | 
|---|
| 209 | #ifndef _IO_cleanup_region_end | 
|---|
| 210 | #define _IO_cleanup_region_end(_Doit) /**/ | 
|---|
| 211 | #endif | 
|---|
| 212 |  | 
|---|
| 213 | #define _IO_need_lock(_fp) \ | 
|---|
| 214 | (((_fp)->_flags2 & _IO_FLAGS2_NEED_LOCK) != 0) | 
|---|
| 215 |  | 
|---|
| 216 | extern int _IO_vfscanf (FILE * __restrict, const char * __restrict, | 
|---|
| 217 | __gnuc_va_list, int *__restrict); | 
|---|
| 218 | extern __ssize_t _IO_padn (FILE *, int, __ssize_t); | 
|---|
| 219 | extern size_t _IO_sgetn (FILE *, void *, size_t); | 
|---|
| 220 |  | 
|---|
| 221 | extern off64_t _IO_seekoff (FILE *, off64_t, int, int); | 
|---|
| 222 | extern off64_t _IO_seekpos (FILE *, off64_t, int); | 
|---|
| 223 |  | 
|---|
| 224 | extern void _IO_free_backup_area (FILE *) __THROW; | 
|---|
| 225 |  | 
|---|
| 226 |  | 
|---|
| 227 | extern wint_t _IO_getwc (FILE *__fp); | 
|---|
| 228 | extern wint_t _IO_putwc (wchar_t __wc, FILE *__fp); | 
|---|
| 229 | extern int _IO_fwide (FILE *__fp, int __mode) __THROW; | 
|---|
| 230 |  | 
|---|
| 231 | #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) | 
|---|
| 232 | #  define _IO_fwide_maybe_incompatible \ | 
|---|
| 233 | (__glibc_unlikely (&_IO_stdin_used == NULL)) | 
|---|
| 234 | extern const int _IO_stdin_used; | 
|---|
| 235 | weak_extern (_IO_stdin_used); | 
|---|
| 236 | #else | 
|---|
| 237 | # define _IO_fwide_maybe_incompatible (0) | 
|---|
| 238 | #endif | 
|---|
| 239 |  | 
|---|
| 240 | /* A special optimized version of the function above.  It optimizes the | 
|---|
| 241 | case of initializing an unoriented byte stream.  */ | 
|---|
| 242 | #define _IO_fwide(__fp, __mode) \ | 
|---|
| 243 | ({ int __result = (__mode);						      \ | 
|---|
| 244 | if (__result < 0 && ! _IO_fwide_maybe_incompatible)		      \ | 
|---|
| 245 | {								      \ | 
|---|
| 246 | if ((__fp)->_mode == 0)					      \ | 
|---|
| 247 | /* We know that all we have to do is to set the flag.  */	      \ | 
|---|
| 248 | (__fp)->_mode = -1;						      \ | 
|---|
| 249 | __result = (__fp)->_mode;					      \ | 
|---|
| 250 | }								      \ | 
|---|
| 251 | else if (__builtin_constant_p (__mode) && (__mode) == 0)		      \ | 
|---|
| 252 | __result = _IO_fwide_maybe_incompatible ? -1 : (__fp)->_mode;	      \ | 
|---|
| 253 | else								      \ | 
|---|
| 254 | __result = _IO_fwide (__fp, __result);				      \ | 
|---|
| 255 | __result; }) | 
|---|
| 256 |  | 
|---|
| 257 | extern int _IO_vfwscanf (FILE * __restrict, const wchar_t * __restrict, | 
|---|
| 258 | __gnuc_va_list, int *__restrict); | 
|---|
| 259 | extern __ssize_t _IO_wpadn (FILE *, wint_t, __ssize_t); | 
|---|
| 260 | extern void _IO_free_wbackup_area (FILE *) __THROW; | 
|---|
| 261 |  | 
|---|
| 262 | #ifdef __LDBL_COMPAT | 
|---|
| 263 | __LDBL_REDIR_DECL (_IO_vfscanf) | 
|---|
| 264 | #endif | 
|---|
| 265 |  | 
|---|
| 266 | libc_hidden_proto (__overflow) | 
|---|
| 267 | libc_hidden_proto (__underflow) | 
|---|
| 268 | libc_hidden_proto (__uflow) | 
|---|
| 269 | libc_hidden_proto (__woverflow) | 
|---|
| 270 | libc_hidden_proto (__wunderflow) | 
|---|
| 271 | libc_hidden_proto (__wuflow) | 
|---|
| 272 | libc_hidden_proto (_IO_free_backup_area) | 
|---|
| 273 | libc_hidden_proto (_IO_free_wbackup_area) | 
|---|
| 274 | libc_hidden_proto (_IO_padn) | 
|---|
| 275 | libc_hidden_proto (_IO_putc) | 
|---|
| 276 | libc_hidden_proto (_IO_sgetn) | 
|---|
| 277 |  | 
|---|
| 278 | #ifdef _IO_MTSAFE_IO | 
|---|
| 279 | # undef _IO_peekc | 
|---|
| 280 | # undef _IO_flockfile | 
|---|
| 281 | # undef _IO_funlockfile | 
|---|
| 282 | # undef _IO_ftrylockfile | 
|---|
| 283 |  | 
|---|
| 284 | # define _IO_peekc(_fp) _IO_peekc_locked (_fp) | 
|---|
| 285 | # if _IO_lock_inexpensive | 
|---|
| 286 | #  define _IO_flockfile(_fp) \ | 
|---|
| 287 | if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_lock (*(_fp)->_lock) | 
|---|
| 288 | #  define _IO_funlockfile(_fp) \ | 
|---|
| 289 | if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_lock_unlock (*(_fp)->_lock) | 
|---|
| 290 | # else | 
|---|
| 291 | #  define _IO_flockfile(_fp) \ | 
|---|
| 292 | if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_flockfile (_fp) | 
|---|
| 293 | #  define _IO_funlockfile(_fp) \ | 
|---|
| 294 | if (((_fp)->_flags & _IO_USER_LOCK) == 0) _IO_funlockfile (_fp) | 
|---|
| 295 | # endif | 
|---|
| 296 | #endif /* _IO_MTSAFE_IO */ | 
|---|
| 297 |  | 
|---|
| 298 | #endif /* _LIBIO_H */ | 
|---|
| 299 |  | 
|---|