]> sourceware.org Git - glibc.git/blob - libio/libio.h
ff67e18c18236bea7861aa97c866470016969334
[glibc.git] / libio / libio.h
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>.
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 <http://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 #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
59
60 #include <shlib-compat.h>
61
62 __BEGIN_DECLS
63
64 /* compatibility defines */
65 #define _STDIO_USES_IOSTREAM
66 #define _IO_UNIFIED_JUMPTABLES 1
67 #define __HAVE_COLUMN
68 #define _IO_file_flags _flags
69
70 /* open modes */
71 #define _IOS_INPUT 1
72 #define _IOS_OUTPUT 2
73 #define _IOS_ATEND 4
74 #define _IOS_APPEND 8
75 #define _IOS_TRUNC 16
76 #define _IOS_NOCREATE 32
77 #define _IOS_NOREPLACE 64
78 #define _IOS_BIN 128
79
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. */
85
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
105
106 #define _IO_FLAGS2_MMAP 1
107 #define _IO_FLAGS2_NOTCANCEL 2
108 #ifdef _LIBC
109 # define _IO_FLAGS2_FORTIFY 4
110 #endif
111 #define _IO_FLAGS2_USER_WBUF 8
112 #ifdef _LIBC
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
117 #endif
118
119 /* These are "formatting flags" matching the iostream fmtflags enum values. */
120 #define _IO_SKIPWS 01
121 #define _IO_LEFT 02
122 #define _IO_RIGHT 04
123 #define _IO_INTERNAL 010
124 #define _IO_DEC 020
125 #define _IO_OCT 040
126 #define _IO_HEX 0100
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
137
138
139 struct _IO_jump_t;
140
141 /* A streammarker remembers a position in a buffer. */
142
143 struct _IO_marker {
144 struct _IO_marker *_next;
145 struct _IO_FILE *_sbuf;
146 /* If _pos >= 0
147 it points to _buf->Gbase()+_pos. FIXME comment */
148 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
149 int _pos;
150 };
151
152 /* This is the structure from the libstdc++ codecvt class. */
153 enum __codecvt_result
154 {
155 __codecvt_ok,
156 __codecvt_partial,
157 __codecvt_error,
158 __codecvt_noconv
159 };
160
161 /* The order of the elements in the following struct must match the order
162 of the virtual functions in the libstdc++ codecvt class. */
163 struct _IO_codecvt
164 {
165 void (*__codecvt_destr) (struct _IO_codecvt *);
166 enum __codecvt_result (*__codecvt_do_out) (struct _IO_codecvt *,
167 __mbstate_t *,
168 const wchar_t *,
169 const wchar_t *,
170 const wchar_t **, char *,
171 char *, char **);
172 enum __codecvt_result (*__codecvt_do_unshift) (struct _IO_codecvt *,
173 __mbstate_t *, char *,
174 char *, char **);
175 enum __codecvt_result (*__codecvt_do_in) (struct _IO_codecvt *,
176 __mbstate_t *,
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 *);
185
186 _IO_iconv_t __cd_in;
187 _IO_iconv_t __cd_out;
188 };
189
190 /* Extra data for wide character streams. */
191 struct _IO_wide_data
192 {
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
204 backup area */
205 wchar_t *_IO_save_end; /* Pointer to end of non-current get area. */
206
207 __mbstate_t _IO_state;
208 __mbstate_t _IO_last_state;
209 struct _IO_codecvt _codecvt;
210
211 wchar_t _shortbuf[1];
212
213 const struct _IO_jump_t *_wide_vtable;
214 };
215
216
217 #ifndef __cplusplus
218 typedef struct _IO_FILE _IO_FILE;
219 #endif
220
221 struct _IO_FILE_plus;
222
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_;
226 #ifndef _LIBC
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_))
230 #else
231 extern _IO_FILE *_IO_stdin attribute_hidden;
232 extern _IO_FILE *_IO_stdout attribute_hidden;
233 extern _IO_FILE *_IO_stderr attribute_hidden;
234 #endif
235
236
237 /* Compatibility names for cookie I/O functions. */
238 #ifdef __USE_GNU
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;
244
245 struct _IO_cookie_file;
246
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);
250 #endif
251
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);
256
257 #if __GNUC__ >= 3
258 # define _IO_BE(expr, res) __builtin_expect ((expr), res)
259 #else
260 # define _IO_BE(expr, res) (expr)
261 #endif
262
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)
269
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)))
281
282 #define _IO_feof_unlocked(_fp) __feof_unlocked_body (_fp)
283 #define _IO_ferror_unlocked(_fp) __ferror_unlocked_body (_fp)
284
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;
289
290 extern int _IO_peekc_locked (_IO_FILE *__fp);
291
292 /* This one is for Emacs. */
293 #define _IO_PENDING_OUTPUT_COUNT(_fp) \
294 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
295
296 extern void _IO_flockfile (_IO_FILE *) __THROW;
297 extern void _IO_funlockfile (_IO_FILE *) __THROW;
298 extern int _IO_ftrylockfile (_IO_FILE *) __THROW;
299
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) /**/
306 #endif
307 #ifndef _IO_cleanup_region_end
308 #define _IO_cleanup_region_end(_Doit) /**/
309 #endif
310
311 #define _IO_need_lock(_fp) \
312 (((_fp)->_flags2 & _IO_FLAGS2_NEED_LOCK) != 0)
313
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,
317 _IO_va_list);
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);
320
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);
323
324 extern void _IO_free_backup_area (_IO_FILE *) __THROW;
325
326
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;
330
331 /* While compiling glibc we have to handle compatibility with very old
332 versions. */
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);
338 #else
339 # define _IO_fwide_maybe_incompatible (0)
340 #endif
341
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) \
347 { \
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; \
352 } \
353 else if (__builtin_constant_p (__mode) && (__mode) == 0) \
354 __result = _IO_fwide_maybe_incompatible ? -1 : (__fp)->_mode; \
355 else \
356 __result = _IO_fwide (__fp, __result); \
357 __result; })
358
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,
362 _IO_va_list);
363 extern _IO_ssize_t _IO_wpadn (_IO_FILE *, wint_t, _IO_ssize_t);
364 extern void _IO_free_wbackup_area (_IO_FILE *) __THROW;
365
366 #ifdef __LDBL_COMPAT
367 __LDBL_REDIR_DECL (_IO_vfscanf)
368 __LDBL_REDIR_DECL (_IO_vfprintf)
369 #endif
370
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)
384
385 #ifdef _IO_MTSAFE_IO
386 # undef _IO_peekc
387 # undef _IO_flockfile
388 # undef _IO_funlockfile
389 # undef _IO_ftrylockfile
390
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)
397 # else
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)
402 # endif
403 #endif /* _IO_MTSAFE_IO */
404
405 __END_DECLS
406
407 #endif /* _LIBIO_H */
This page took 0.053729 seconds and 4 git commands to generate.