Update.
[glibc.git] / libio / libio.h
blob8fdc55a8909c65f8b36bbdabe6b37d3b46a2885c
1 /* Copyright (C) 1991,92,93,94,95,97,98,99,2000 Free Software Foundation, Inc.
2 This file is part of the GNU IO Library.
3 Written by Per Bothner <bothner@cygnus.com>.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2, or (at
8 your option) any later version.
10 This library is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING. If not, write to
17 the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
18 MA 02111-1307, USA.
20 As a special exception, if you link this library with files
21 compiled with a GNU compiler to produce an executable, this does
22 not cause the resulting executable to be covered by the GNU General
23 Public License. This exception does not however invalidate any
24 other reasons why the executable file might be covered by the GNU
25 General Public License. */
27 #ifndef _IO_STDIO_H
28 #define _IO_STDIO_H
30 #include <_G_config.h>
31 #define _IO_pos_t _G_fpos_t /* obsolete */
32 #define _IO_fpos_t _G_fpos_t
33 #define _IO_fpos64_t _G_fpos64_t
34 #define _IO_size_t _G_size_t
35 #define _IO_ssize_t _G_ssize_t
36 #define _IO_off_t _G_off_t
37 #define _IO_off64_t _G_off64_t
38 #define _IO_pid_t _G_pid_t
39 #define _IO_uid_t _G_uid_t
40 #define _IO_iconv_t _G_iconv_t
41 #define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT
42 #define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
43 #define _IO_BUFSIZ _G_BUFSIZ
44 #define _IO_va_list _G_va_list
45 #define _IO_wint_t _G_wint_t
47 #ifdef _G_NEED_STDARG_H
48 /* This define avoids name pollution if we're using GNU stdarg.h */
49 # define __need___va_list
50 # include <stdarg.h>
51 # ifdef __GNUC_VA_LIST
52 # undef _IO_va_list
53 # define _IO_va_list __gnuc_va_list
54 # endif /* __GNUC_VA_LIST */
55 #endif
57 #ifndef __P
58 # if _G_HAVE_SYS_CDEFS
59 # include <sys/cdefs.h>
60 # else
61 # ifdef __STDC__
62 # define __P(p) p
63 # define __PMT(p) p
64 # else
65 # define __P(p) ()
66 # define __PMT(p) ()
67 # endif
68 # endif
69 #endif /*!__P*/
71 /* For backward compatibility */
72 #ifndef _PARAMS
73 # define _PARAMS(protos) __P(protos)
74 #endif /*!_PARAMS*/
76 #ifndef __STDC__
77 # ifndef const
78 # define const
79 # endif
80 #endif
81 #define _IO_UNIFIED_JUMPTABLES 1
82 #ifndef _G_HAVE_PRINTF_FP
83 # define _IO_USE_DTOA 1
84 #endif
86 #ifndef EOF
87 # define EOF (-1)
88 #endif
89 #ifndef NULL
90 # if defined __GNUG__ && \
91 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
92 # define NULL (__null)
93 # else
94 # if !defined(__cplusplus)
95 # define NULL ((void*)0)
96 # else
97 # define NULL (0)
98 # endif
99 # endif
100 #endif
102 #define _IOS_INPUT 1
103 #define _IOS_OUTPUT 2
104 #define _IOS_ATEND 4
105 #define _IOS_APPEND 8
106 #define _IOS_TRUNC 16
107 #define _IOS_NOCREATE 32
108 #define _IOS_NOREPLACE 64
109 #define _IOS_BIN 128
111 /* Magic numbers and bits for the _flags field.
112 The magic numbers use the high-order bits of _flags;
113 the remaining bits are available for variable flags.
114 Note: The magic numbers must all be negative if stdio
115 emulation is desired. */
117 #define _IO_MAGIC 0xFBAD0000 /* Magic number */
118 #define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
119 #define _IO_MAGIC_MASK 0xFFFF0000
120 #define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */
121 #define _IO_UNBUFFERED 2
122 #define _IO_NO_READS 4 /* Reading not allowed */
123 #define _IO_NO_WRITES 8 /* Writing not allowd */
124 #define _IO_EOF_SEEN 0x10
125 #define _IO_ERR_SEEN 0x20
126 #define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */
127 #define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/
128 #define _IO_IN_BACKUP 0x100
129 #define _IO_LINE_BUF 0x200
130 #define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */
131 #define _IO_CURRENTLY_PUTTING 0x800
132 #define _IO_IS_APPENDING 0x1000
133 #define _IO_IS_FILEBUF 0x2000
134 #define _IO_BAD_SEEN 0x4000
136 /* These are "formatting flags" matching the iostream fmtflags enum values. */
137 #define _IO_SKIPWS 01
138 #define _IO_LEFT 02
139 #define _IO_RIGHT 04
140 #define _IO_INTERNAL 010
141 #define _IO_DEC 020
142 #define _IO_OCT 040
143 #define _IO_HEX 0100
144 #define _IO_SHOWBASE 0200
145 #define _IO_SHOWPOINT 0400
146 #define _IO_UPPERCASE 01000
147 #define _IO_SHOWPOS 02000
148 #define _IO_SCIENTIFIC 04000
149 #define _IO_FIXED 010000
150 #define _IO_UNITBUF 020000
151 #define _IO_STDIO 040000
152 #define _IO_DONT_CLOSE 0100000
153 #define _IO_BOOLALPHA 0200000
156 struct _IO_jump_t; struct _IO_FILE;
158 /* Handle lock. */
159 #ifdef _IO_MTSAFE_IO
160 # if defined __GLIBC__ && __GLIBC__ >= 2
161 # include <bits/stdio-lock.h>
162 # else
163 /*# include <comthread.h>*/
164 # endif
165 #else
166 typedef void _IO_lock_t;
167 #endif
170 /* A streammarker remembers a position in a buffer. */
172 struct _IO_marker {
173 struct _IO_marker *_next;
174 struct _IO_FILE *_sbuf;
175 /* If _pos >= 0
176 it points to _buf->Gbase()+_pos. FIXME comment */
177 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
178 int _pos;
179 #if 0
180 void set_streampos(streampos sp) { _spos = sp; }
181 void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
182 public:
183 streammarker(streambuf *sb);
184 ~streammarker();
185 int saving() { return _spos == -2; }
186 int delta(streammarker&);
187 int delta();
188 #endif
191 /* This is the structure from the libstdc++ codecvt class. */
192 enum __codecvt_result
194 __codecvt_ok,
195 __codecvt_partial,
196 __codecvt_error,
197 __codecvt_noconv
200 /* The order of the elements in the following struct must match the order
201 of the virtual functions in the libstdc++ codecvt class. */
202 struct _IO_codecvt
204 void (*__codecvt_destr) (struct _IO_codecvt *);
205 enum __codecvt_result (*__codecvt_do_out) (struct _IO_codecvt *,
206 __mbstate_t *,
207 const wchar_t *,
208 const wchar_t *,
209 const wchar_t **, char *,
210 char *, char **);
211 enum __codecvt_result (*__codecvt_do_unshift) (struct _IO_codecvt *,
212 __mbstate_t *, char *,
213 char *, char **);
214 enum __codecvt_result (*__codecvt_do_in) (struct _IO_codecvt *,
215 __mbstate_t *,
216 const char *, const char *,
217 const char **, wchar_t *,
218 wchar_t *, wchar_t **);
219 int (*__codecvt_do_encoding) (struct _IO_codecvt *);
220 int (*__codecvt_do_always_noconv) (struct _IO_codecvt *);
221 int (*__codecvt_do_length) (struct _IO_codecvt *, __mbstate_t *,
222 const char *, const char *, _IO_size_t);
223 int (*__codecvt_do_max_length) (struct _IO_codecvt *);
225 _IO_iconv_t __cd_in;
226 _IO_iconv_t __cd_out;
229 /* Extra data for wide character streams. */
230 struct _IO_wide_data
232 wchar_t *_IO_read_ptr; /* Current read pointer */
233 wchar_t *_IO_read_end; /* End of get area. */
234 wchar_t *_IO_read_base; /* Start of putback+get area. */
235 wchar_t *_IO_write_base; /* Start of put area. */
236 wchar_t *_IO_write_ptr; /* Current put pointer. */
237 wchar_t *_IO_write_end; /* End of put area. */
238 wchar_t *_IO_buf_base; /* Start of reserve area. */
239 wchar_t *_IO_buf_end; /* End of reserve area. */
240 /* The following fields are used to support backing up and undo. */
241 wchar_t *_IO_save_base; /* Pointer to start of non-current get area. */
242 wchar_t *_IO_backup_base; /* Pointer to first valid character of
243 backup area */
244 wchar_t *_IO_save_end; /* Pointer to end of non-current get area. */
246 __mbstate_t _IO_state;
247 __mbstate_t _IO_last_state;
248 struct _IO_codecvt _codecvt;
250 wchar_t _shortbuf[1];
252 struct _IO_jump_t *_wide_vtable;
255 struct _IO_FILE {
256 int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
257 #define _IO_file_flags _flags
259 /* The following pointers correspond to the C++ streambuf protocol. */
260 /* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
261 char* _IO_read_ptr; /* Current read pointer */
262 char* _IO_read_end; /* End of get area. */
263 char* _IO_read_base; /* Start of putback+get area. */
264 char* _IO_write_base; /* Start of put area. */
265 char* _IO_write_ptr; /* Current put pointer. */
266 char* _IO_write_end; /* End of put area. */
267 char* _IO_buf_base; /* Start of reserve area. */
268 char* _IO_buf_end; /* End of reserve area. */
269 /* The following fields are used to support backing up and undo. */
270 char *_IO_save_base; /* Pointer to start of non-current get area. */
271 char *_IO_backup_base; /* Pointer to first valid character of backup area */
272 char *_IO_save_end; /* Pointer to end of non-current get area. */
274 struct _IO_marker *_markers;
276 struct _IO_FILE *_chain;
278 int _fileno;
279 int _blksize;
280 _IO_off_t _old_offset; /* This used to be _offset but it's too small. */
282 #define __HAVE_COLUMN /* temporary */
283 /* 1+column number of pbase(); 0 is unknown. */
284 unsigned short _cur_column;
285 signed char _vtable_offset;
286 char _shortbuf[1];
288 /* char* _save_gptr; char* _save_egptr; */
290 _IO_lock_t *_lock;
291 #ifdef _IO_USE_OLD_IO_FILE
294 struct _IO_FILE_complete
296 struct _IO_FILE _file;
297 #endif
298 #if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001
299 _IO_off64_t _offset;
300 /* Wide character stream stuff. */
301 struct _IO_codecvt *_codecvt;
302 struct _IO_wide_data *_wide_data;
303 int _mode;
304 /* Make sure we don't get into trouble again. */
305 char _unused2[15 * sizeof (int) - 2 * sizeof (void *)];
306 #endif
309 #ifndef __cplusplus
310 typedef struct _IO_FILE _IO_FILE;
311 #endif
313 struct _IO_FILE_plus;
314 extern struct _IO_FILE_plus _IO_2_1_stdin_;
315 extern struct _IO_FILE_plus _IO_2_1_stdout_;
316 extern struct _IO_FILE_plus _IO_2_1_stderr_;
317 #ifndef _LIBC
318 #define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))
319 #define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
320 #define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
321 #else
322 extern _IO_FILE *_IO_stdin;
323 extern _IO_FILE *_IO_stdout;
324 extern _IO_FILE *_IO_stderr;
325 #endif
328 /* Functions to do I/O and file management for a stream. */
330 /* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF.
331 Return number of bytes read. */
332 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
334 /* Write N bytes pointed to by BUF to COOKIE. Write all N bytes
335 unless there is an error. Return number of bytes written, or -1 if
336 there is an error without writing anything. If the file has been
337 opened for append (__mode.__append set), then set the file pointer
338 to the end of the file and then do the write; if not, just write at
339 the current file pointer. */
340 typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf,
341 size_t __n);
343 /* Move COOKIE's file position to *POS bytes from the
344 beginning of the file (if W is SEEK_SET),
345 the current position (if W is SEEK_CUR),
346 or the end of the file (if W is SEEK_END).
347 Set *POS to the new file position.
348 Returns zero if successful, nonzero if not. */
349 typedef int __io_seek_fn (void *__cookie, _IO_off64_t *__pos, int __w);
351 /* Close COOKIE. */
352 typedef int __io_close_fn (void *__cookie);
355 #ifdef _GNU_SOURCE
356 /* User-visible names for the above. */
357 typedef __io_read_fn cookie_read_function_t;
358 typedef __io_write_fn cookie_write_function_t;
359 typedef __io_seek_fn cookie_seek_function_t;
360 typedef __io_close_fn cookie_close_function_t;
362 /* The structure with the cookie function pointers. */
363 typedef struct
365 __io_read_fn *read; /* Read bytes. */
366 __io_write_fn *write; /* Write bytes. */
367 __io_seek_fn *seek; /* Seek/tell file position. */
368 __io_close_fn *close; /* Close file. */
369 } _IO_cookie_io_functions_t;
370 typedef _IO_cookie_io_functions_t cookie_io_functions_t;
372 /* Special file type for fopencookie function. */
373 struct _IO_cookie_file
375 struct _IO_FILE __file;
376 const void *__vtable;
377 void *__cookie;
378 _IO_cookie_io_functions_t __io_functions;
381 /* Initialize one of those. */
382 extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write,
383 void *__cookie, _IO_cookie_io_functions_t __fns);
384 #endif
387 #ifdef __cplusplus
388 extern "C" {
389 #endif
391 extern int __underflow (_IO_FILE *) __THROW;
392 extern int __uflow (_IO_FILE *) __THROW;
393 extern int __overflow (_IO_FILE *, int) __THROW;
394 extern _IO_wint_t __wunderflow (_IO_FILE *) __THROW;
395 extern _IO_wint_t __wuflow (_IO_FILE *) __THROW;
396 extern _IO_wint_t __woverflow (_IO_FILE *, _IO_wint_t) __THROW;
398 #define _IO_getc_unlocked(_fp) \
399 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) \
400 : *(unsigned char *) (_fp)->_IO_read_ptr++)
401 #define _IO_peekc_unlocked(_fp) \
402 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
403 && __underflow (_fp) == EOF ? EOF \
404 : *(unsigned char *) (_fp)->_IO_read_ptr)
405 #define _IO_putc_unlocked(_ch, _fp) \
406 (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
407 ? __overflow (_fp, (unsigned char) (_ch)) \
408 : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
410 #define _IO_getwc_unlocked(_fp) \
411 ((_fp)->_wide_data->_IO_read_ptr >= (_fp)->_wide_data->_IO_read_end \
412 ? __wuflow (_fp) : (_IO_wint_t) *(_fp)->_wide_data->_IO_read_ptr++)
413 #define _IO_putwc_unlocked(_wch, _fp) \
414 ((_fp)->_wide_data->_IO_write_ptr >= (_fp)->_wide_data->_IO_write_end \
415 ? __woverflow (_fp, _wch) \
416 : (_IO_wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch)))
418 #define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
419 #define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
421 extern int _IO_getc (_IO_FILE *__fp) __THROW;
422 extern int _IO_putc (int __c, _IO_FILE *__fp) __THROW;
423 extern _IO_wint_t _IO_getwc (_IO_FILE *__fp) __THROW;
424 extern _IO_wint_t _IO_putwc (wchar_t __wc, _IO_FILE *__fp) __THROW;
425 extern int _IO_feof (_IO_FILE *__fp) __THROW;
426 extern int _IO_ferror (_IO_FILE *__fp) __THROW;
428 extern int _IO_peekc_locked (_IO_FILE *__fp) __THROW;
430 extern int _IO_fwide (_IO_FILE *__fp, int __mode) __THROW;
431 #if __GNUC__ >= 2
432 /* A special optimized version of the function above. It optimizes the
433 case of initializing an unoriented byte stream. */
434 # define _IO_fwide(__fp, __mode) \
435 ({ int __result = (__mode); \
436 if (__result < 0) \
438 if ((__fp)->_mode == 0) \
439 /* We know that all we have to do is to set the flag. */ \
440 (__fp)->_mode = -1; \
441 __result = (__fp)->_mode; \
443 else \
444 __result = _IO_fwide (__fp, __result); \
445 __result; })
446 #endif
448 /* This one is for Emacs. */
449 #define _IO_PENDING_OUTPUT_COUNT(_fp) \
450 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
452 extern void _IO_flockfile (_IO_FILE *) __THROW;
453 extern void _IO_funlockfile (_IO_FILE *) __THROW;
454 extern int _IO_ftrylockfile (_IO_FILE *) __THROW;
456 #ifdef _IO_MTSAFE_IO
457 # define _IO_peekc(_fp) _IO_peekc_locked (_fp)
458 #else
459 # define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
460 # define _IO_flockfile(_fp) /**/
461 # define _IO_funlockfile(_fp) /**/
462 # define _IO_ftrylockfile(_fp) /**/
463 # define _IO_cleanup_region_start(_fct, _fp) /**/
464 # define _IO_cleanup_region_end(_Doit) /**/
465 #endif /* !_IO_MTSAFE_IO */
467 extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
468 _IO_va_list, int *__restrict) __THROW;
469 extern int _IO_vfwscanf (_IO_FILE * __restrict, const wchar_t * __restrict,
470 _IO_va_list, int *__restrict) __THROW;
471 extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
472 _IO_va_list) __THROW;
473 extern int _IO_vfwprintf (_IO_FILE *__restrict, const wchar_t *__restrict,
474 _IO_va_list) __THROW;
475 extern _IO_ssize_t _IO_padn (_IO_FILE *, int, _IO_ssize_t) __THROW;
476 extern _IO_ssize_t _IO_wpadn (_IO_FILE *, wint_t, _IO_ssize_t) __THROW;
477 extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t) __THROW;
479 extern _IO_off64_t _IO_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
480 extern _IO_off64_t _IO_seekpos (_IO_FILE *, _IO_off64_t, int) __THROW;
482 extern void _IO_free_backup_area (_IO_FILE *) __THROW;
483 extern void _IO_free_wbackup_area (_IO_FILE *) __THROW;
485 #ifdef __cplusplus
487 #endif
489 #endif /* _IO_STDIO_H */