2002-11-21 Phil Edwards <pme@gcc.gnu.org>
[official-gcc.git] / libstdc++-v3 / libio / libio.h
blobe2a2a15bcb0d9d541d6324707950c91355ce1349
1 /* Copyright (C) 1991,92,93,94,95,97,98,99,2000,2001 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 /* ALL of these should be defined in _G_config.h */
32 #define _IO_pos_t _G_fpos_t /* obsolete */
33 #define _IO_fpos_t _G_fpos_t
34 #define _IO_fpos64_t _G_fpos64_t
35 #define _IO_size_t _G_size_t
36 #define _IO_ssize_t _G_ssize_t
37 #define _IO_off_t _G_off_t
38 #define _IO_off64_t _G_off64_t
39 #define _IO_pid_t _G_pid_t
40 #define _IO_uid_t _G_uid_t
41 #define _IO_iconv_t _G_iconv_t
42 #define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT
43 #define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
44 #define _IO_BUFSIZ _G_BUFSIZ
45 #define _IO_va_list _G_va_list
46 #define _IO_wint_t _G_wint_t
48 #ifdef _G_NEED_STDARG_H
49 /* This define avoids name pollution if we're using GNU stdarg.h */
50 # define __need___va_list
51 # include <stdarg.h>
52 # ifdef __GNUC_VA_LIST
53 # undef _IO_va_list
54 # define _IO_va_list __gnuc_va_list
55 # endif /* __GNUC_VA_LIST */
56 #endif
58 #ifndef __THROW
59 # ifdef __cplusplus
60 # define __THROW throw ()
61 # else
62 # define __THROW
63 # endif
64 #endif /* not __THROW */
66 #ifndef __P
67 # define __P(p) p __THROW
68 #endif /* not __P */
70 #ifndef __PMT
71 # define __PMT(p) p
72 #endif /* not __PMT */
74 /* For backward compatibility */
75 #ifndef _PARAMS
76 # define _PARAMS(protos) __P(protos)
77 #endif /*!_PARAMS*/
79 #ifndef __STDC__
80 # ifndef const
81 # define const
82 # endif
83 #endif
84 #define _IO_UNIFIED_JUMPTABLES 1
85 #ifndef _G_HAVE_PRINTF_FP
86 # define _IO_USE_DTOA 1
87 #endif
89 #ifndef EOF
90 # define EOF (-1)
91 #endif
92 #ifndef NULL
93 # if defined __GNUG__ && \
94 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
95 # define NULL (__null)
96 # else
97 # if !defined(__cplusplus)
98 # define NULL ((void*)0)
99 # else
100 # define NULL (0)
101 # endif
102 # endif
103 #endif
105 #define _IOS_INPUT 1
106 #define _IOS_OUTPUT 2
107 #define _IOS_ATEND 4
108 #define _IOS_APPEND 8
109 #define _IOS_TRUNC 16
110 #define _IOS_NOCREATE 32
111 #define _IOS_NOREPLACE 64
112 #define _IOS_BIN 128
114 /* Magic numbers and bits for the _flags field.
115 The magic numbers use the high-order bits of _flags;
116 the remaining bits are available for variable flags.
117 Note: The magic numbers must all be negative if stdio
118 emulation is desired. */
120 #define _IO_MAGIC 0xFBAD0000 /* Magic number */
121 #define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
122 #define _IO_MAGIC_MASK 0xFFFF0000
123 #define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */
124 #define _IO_UNBUFFERED 2
125 #define _IO_NO_READS 4 /* Reading not allowed */
126 #define _IO_NO_WRITES 8 /* Writing not allowd */
127 #define _IO_EOF_SEEN 0x10
128 #define _IO_ERR_SEEN 0x20
129 #define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */
130 #define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/
131 #define _IO_IN_BACKUP 0x100
132 #define _IO_LINE_BUF 0x200
133 #define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */
134 #define _IO_CURRENTLY_PUTTING 0x800
135 #define _IO_IS_APPENDING 0x1000
136 #define _IO_IS_FILEBUF 0x2000
137 #define _IO_BAD_SEEN 0x4000
138 #define _IO_USER_LOCK 0x8000
140 /* These are "formatting flags" matching the iostream fmtflags enum values. */
141 #define _IO_SKIPWS 01
142 #define _IO_LEFT 02
143 #define _IO_RIGHT 04
144 #define _IO_INTERNAL 010
145 #define _IO_DEC 020
146 #define _IO_OCT 040
147 #define _IO_HEX 0100
148 #define _IO_SHOWBASE 0200
149 #define _IO_SHOWPOINT 0400
150 #define _IO_UPPERCASE 01000
151 #define _IO_SHOWPOS 02000
152 #define _IO_SCIENTIFIC 04000
153 #define _IO_FIXED 010000
154 #define _IO_UNITBUF 020000
155 #define _IO_STDIO 040000
156 #define _IO_DONT_CLOSE 0100000
157 #define _IO_BOOLALPHA 0200000
160 struct _IO_jump_t; struct _IO_FILE;
162 /* Handle lock. */
163 #ifdef _IO_MTSAFE_IO
164 # if defined __GLIBC__ && __GLIBC__ >= 2
165 # if __GLIBC_MINOR__ == 0
166 # include <stdio-lock.h>
167 # else
168 # include <bits/stdio-lock.h>
169 # endif
170 # else
171 /*# include <comthread.h>*/
172 # endif
173 #else
174 typedef void _IO_lock_t;
175 #endif
178 /* A streammarker remembers a position in a buffer. */
180 struct _IO_marker {
181 struct _IO_marker *_next;
182 struct _IO_FILE *_sbuf;
183 /* If _pos >= 0
184 it points to _buf->Gbase()+_pos. FIXME comment */
185 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
186 int _pos;
187 #if 0
188 void set_streampos(streampos sp) { _spos = sp; }
189 void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
190 public:
191 streammarker(streambuf *sb);
192 ~streammarker();
193 int saving() { return _spos == -2; }
194 int delta(streammarker&);
195 int delta();
196 #endif
199 /* This is the structure from the libstdc++ codecvt class. */
200 enum __codecvt_result
202 __codecvt_ok,
203 __codecvt_partial,
204 __codecvt_error,
205 __codecvt_noconv
208 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
209 /* The order of the elements in the following struct must match the order
210 of the virtual functions in the libstdc++ codecvt class. */
211 struct _IO_codecvt
213 void (*__codecvt_destr) (struct _IO_codecvt *);
214 enum __codecvt_result (*__codecvt_do_out) (struct _IO_codecvt *,
215 __c_mbstate_t *,
216 const wchar_t *,
217 const wchar_t *,
218 const wchar_t **, char *,
219 char *, char **);
220 enum __codecvt_result (*__codecvt_do_unshift) (struct _IO_codecvt *,
221 __c_mbstate_t *, char *,
222 char *, char **);
223 enum __codecvt_result (*__codecvt_do_in) (struct _IO_codecvt *,
224 __c_mbstate_t *,
225 const char *, const char *,
226 const char **, wchar_t *,
227 wchar_t *, wchar_t **);
228 int (*__codecvt_do_encoding) (struct _IO_codecvt *);
229 int (*__codecvt_do_always_noconv) (struct _IO_codecvt *);
230 int (*__codecvt_do_length) (struct _IO_codecvt *, __c_mbstate_t *,
231 const char *, const char *, _IO_size_t);
232 int (*__codecvt_do_max_length) (struct _IO_codecvt *);
234 _IO_iconv_t __cd_in;
235 _IO_iconv_t __cd_out;
238 /* Extra data for wide character streams. */
239 struct _IO_wide_data
241 wchar_t *_IO_read_ptr; /* Current read pointer */
242 wchar_t *_IO_read_end; /* End of get area. */
243 wchar_t *_IO_read_base; /* Start of putback+get area. */
244 wchar_t *_IO_write_base; /* Start of put area. */
245 wchar_t *_IO_write_ptr; /* Current put pointer. */
246 wchar_t *_IO_write_end; /* End of put area. */
247 wchar_t *_IO_buf_base; /* Start of reserve area. */
248 wchar_t *_IO_buf_end; /* End of reserve area. */
249 /* The following fields are used to support backing up and undo. */
250 wchar_t *_IO_save_base; /* Pointer to start of non-current get area. */
251 wchar_t *_IO_backup_base; /* Pointer to first valid character of
252 backup area */
253 wchar_t *_IO_save_end; /* Pointer to end of non-current get area. */
255 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
256 __c_mbstate_t _IO_state;
257 __c_mbstate_t _IO_last_state;
258 #endif
259 struct _IO_codecvt _codecvt;
261 wchar_t _shortbuf[1];
263 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
264 struct _IO_jump_t *_wide_vtable;
265 #endif
267 #else /* !(defined _LIBC || defined _GLIBCPP_USE_WCHAR_T) */
268 /* Because _IO_no_init unconditionally takes a `_IO_wide_data*' as its
269 last parameter we must still define this type. We intentionally
270 leave it incomplete to prevent any use of this type when we are not
271 supporting wide characters. */
272 struct _IO_wide_data;
273 #endif /* !(defined _LIBC || defined _GLIBCPP_USE_WCHAR_T) */
275 struct _IO_FILE {
276 int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
277 #define _IO_file_flags _flags
279 /* The following pointers correspond to the C++ streambuf protocol. */
280 /* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
281 char* _IO_read_ptr; /* Current read pointer */
282 char* _IO_read_end; /* End of get area. */
283 char* _IO_read_base; /* Start of putback+get area. */
284 char* _IO_write_base; /* Start of put area. */
285 char* _IO_write_ptr; /* Current put pointer. */
286 char* _IO_write_end; /* End of put area. */
287 char* _IO_buf_base; /* Start of reserve area. */
288 char* _IO_buf_end; /* End of reserve area. */
289 /* The following fields are used to support backing up and undo. */
290 char *_IO_save_base; /* Pointer to start of non-current get area. */
291 char *_IO_backup_base; /* Pointer to first valid character of backup area */
292 char *_IO_save_end; /* Pointer to end of non-current get area. */
294 struct _IO_marker *_markers;
296 struct _IO_FILE *_chain;
298 int _fileno;
299 int _blksize;
300 _IO_off_t _old_offset; /* This used to be _offset but it's too small. */
302 #define __HAVE_COLUMN /* temporary */
303 /* 1+column number of pbase(); 0 is unknown. */
304 unsigned short _cur_column;
305 signed char _vtable_offset;
306 char _shortbuf[1];
308 /* char* _save_gptr; char* _save_egptr; */
310 _IO_lock_t *_lock;
311 #ifdef _IO_USE_OLD_IO_FILE
314 struct _IO_FILE_complete
316 struct _IO_FILE _file;
317 #endif
318 #if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001
319 _IO_off64_t _offset;
320 # if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
321 /* Wide character stream stuff. */
322 struct _IO_codecvt *_codecvt;
323 struct _IO_wide_data *_wide_data;
324 # else
325 void *__pad1;
326 void *__pad2;
327 # endif
328 int _mode;
329 /* Make sure we don't get into trouble again. */
330 char _unused2[15 * sizeof (int) - 2 * sizeof (void *)];
331 #endif
334 #ifndef __cplusplus
335 typedef struct _IO_FILE _IO_FILE;
336 #endif
338 struct _IO_FILE_plus;
340 extern struct _IO_FILE_plus _IO_2_1_stdin_;
341 extern struct _IO_FILE_plus _IO_2_1_stdout_;
342 extern struct _IO_FILE_plus _IO_2_1_stderr_;
343 #ifndef _LIBC
344 #define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))
345 #define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
346 #define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
347 #else
348 extern _IO_FILE *_IO_stdin;
349 extern _IO_FILE *_IO_stdout;
350 extern _IO_FILE *_IO_stderr;
351 #endif
354 /* Functions to do I/O and file management for a stream. */
356 /* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF.
357 Return number of bytes read. */
358 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
360 /* Write N bytes pointed to by BUF to COOKIE. Write all N bytes
361 unless there is an error. Return number of bytes written, or -1 if
362 there is an error without writing anything. If the file has been
363 opened for append (__mode.__append set), then set the file pointer
364 to the end of the file and then do the write; if not, just write at
365 the current file pointer. */
366 typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf,
367 size_t __n);
369 /* Move COOKIE's file position to *POS bytes from the
370 beginning of the file (if W is SEEK_SET),
371 the current position (if W is SEEK_CUR),
372 or the end of the file (if W is SEEK_END).
373 Set *POS to the new file position.
374 Returns zero if successful, nonzero if not. */
375 typedef int __io_seek_fn (void *__cookie, _IO_off64_t *__pos, int __w);
377 /* Close COOKIE. */
378 typedef int __io_close_fn (void *__cookie);
381 #ifdef _GNU_SOURCE
382 /* User-visible names for the above. */
383 typedef __io_read_fn cookie_read_function_t;
384 typedef __io_write_fn cookie_write_function_t;
385 typedef __io_seek_fn cookie_seek_function_t;
386 typedef __io_close_fn cookie_close_function_t;
388 /* The structure with the cookie function pointers. */
389 typedef struct
391 __io_read_fn *read; /* Read bytes. */
392 __io_write_fn *write; /* Write bytes. */
393 __io_seek_fn *seek; /* Seek/tell file position. */
394 __io_close_fn *close; /* Close file. */
395 } _IO_cookie_io_functions_t;
396 typedef _IO_cookie_io_functions_t cookie_io_functions_t;
398 struct _IO_cookie_file;
400 /* Initialize one of those. */
401 extern void _IO_cookie_init (struct _IO_cookie_file *__cfile, int __read_write,
402 void *__cookie, _IO_cookie_io_functions_t __fns);
403 #endif
406 #ifdef __cplusplus
407 extern "C" {
408 #endif
410 extern int __underflow (_IO_FILE *) __THROW;
411 extern int __uflow (_IO_FILE *) __THROW;
412 extern int __overflow (_IO_FILE *, int) __THROW;
413 extern _IO_wint_t __wunderflow (_IO_FILE *) __THROW;
414 extern _IO_wint_t __wuflow (_IO_FILE *) __THROW;
415 extern _IO_wint_t __woverflow (_IO_FILE *, _IO_wint_t) __THROW;
417 #define _IO_getc_unlocked(_fp) \
418 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) \
419 : *(unsigned char *) (_fp)->_IO_read_ptr++)
420 #define _IO_peekc_unlocked(_fp) \
421 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
422 && __underflow (_fp) == EOF ? EOF \
423 : *(unsigned char *) (_fp)->_IO_read_ptr)
424 #define _IO_putc_unlocked(_ch, _fp) \
425 (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
426 ? __overflow (_fp, (unsigned char) (_ch)) \
427 : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
429 #define _IO_getwc_unlocked(_fp) \
430 ((_fp)->_wide_data->_IO_read_ptr >= (_fp)->_wide_data->_IO_read_end \
431 ? __wuflow (_fp) : (_IO_wint_t) *(_fp)->_wide_data->_IO_read_ptr++)
432 #define _IO_putwc_unlocked(_wch, _fp) \
433 ((_fp)->_wide_data->_IO_write_ptr >= (_fp)->_wide_data->_IO_write_end \
434 ? __woverflow (_fp, _wch) \
435 : (_IO_wint_t) (*(_fp)->_wide_data->_IO_write_ptr++ = (_wch)))
437 #define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
438 #define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
440 extern int _IO_getc (_IO_FILE *__fp) __THROW;
441 extern int _IO_putc (int __c, _IO_FILE *__fp) __THROW;
442 extern int _IO_feof (_IO_FILE *__fp) __THROW;
443 extern int _IO_ferror (_IO_FILE *__fp) __THROW;
445 extern int _IO_peekc_locked (_IO_FILE *__fp) __THROW;
447 /* This one is for Emacs. */
448 #define _IO_PENDING_OUTPUT_COUNT(_fp) \
449 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
451 extern void _IO_flockfile (_IO_FILE *) __THROW;
452 extern void _IO_funlockfile (_IO_FILE *) __THROW;
453 extern int _IO_ftrylockfile (_IO_FILE *) __THROW;
455 #ifdef _IO_MTSAFE_IO
456 # define _IO_peekc(_fp) _IO_peekc_locked (_fp)
457 #else
458 # define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
459 # define _IO_flockfile(_fp) /**/
460 # define _IO_funlockfile(_fp) /**/
461 # define _IO_ftrylockfile(_fp) /**/
462 # define _IO_cleanup_region_start(_fct, _fp) /**/
463 # define _IO_cleanup_region_end(_Doit) /**/
464 #endif /* !_IO_MTSAFE_IO */
466 extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict,
467 _IO_va_list, int *__restrict) __THROW;
468 extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict,
469 _IO_va_list) __THROW;
470 extern _IO_ssize_t _IO_padn (_IO_FILE *, int, _IO_ssize_t) __THROW;
471 extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t) __THROW;
473 extern _IO_off64_t _IO_seekoff (_IO_FILE *, _IO_off64_t, int, int) __THROW;
474 extern _IO_off64_t _IO_seekpos (_IO_FILE *, _IO_off64_t, int) __THROW;
476 extern void _IO_free_backup_area (_IO_FILE *) __THROW;
478 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
479 extern _IO_wint_t _IO_getwc (_IO_FILE *__fp) __THROW;
480 extern _IO_wint_t _IO_putwc (wchar_t __wc, _IO_FILE *__fp) __THROW;
481 extern int _IO_fwide (_IO_FILE *__fp, int __mode) __THROW;
482 # if __GNUC__ >= 2
483 /* A special optimized version of the function above. It optimizes the
484 case of initializing an unoriented byte stream. */
485 # define _IO_fwide(__fp, __mode) \
486 ({ int __result = (__mode); \
487 if (__result < 0) \
489 if ((__fp)->_mode == 0) \
490 /* We know that all we have to do is to set the flag. */ \
491 (__fp)->_mode = -1; \
492 __result = (__fp)->_mode; \
494 else \
495 __result = _IO_fwide (__fp, __result); \
496 __result; })
497 # endif
499 extern int _IO_vfwscanf (_IO_FILE * __restrict, const wchar_t * __restrict,
500 _IO_va_list, int *__restrict) __THROW;
501 extern int _IO_vfwprintf (_IO_FILE *__restrict, const wchar_t *__restrict,
502 _IO_va_list) __THROW;
503 extern _IO_ssize_t _IO_wpadn (_IO_FILE *, wint_t, _IO_ssize_t) __THROW;
504 extern void _IO_free_wbackup_area (_IO_FILE *) __THROW;
505 #endif
507 #ifdef __cplusplus
509 #endif
511 #endif /* _IO_STDIO_H */