]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/libio.h
Update.
[thirdparty/glibc.git] / libio / libio.h
CommitLineData
fdacb17d 1/* Copyright (C) 1991, 92, 93, 94, 95, 97, 98 Free Software Foundation, Inc.
40a55d20
UD
2 This file is part of the GNU IO Library.
3 Written by Per Bothner <bothner@cygnus.com>.
4
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.
9
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.
14
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.
19
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. */
96aa2d94
RM
26
27#ifndef _IO_STDIO_H
28#define _IO_STDIO_H
29
30#include <_G_config.h>
31#define _IO_pos_t _G_fpos_t /* obsolete */
32#define _IO_fpos_t _G_fpos_t
dfd2257a 33#define _IO_fpos64_t _G_fpos64_t
96aa2d94
RM
34#define _IO_size_t _G_size_t
35#define _IO_ssize_t _G_ssize_t
36#define _IO_off_t _G_off_t
dfd2257a 37#define _IO_off64_t _G_off64_t
96aa2d94
RM
38#define _IO_pid_t _G_pid_t
39#define _IO_uid_t _G_uid_t
40#define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT
41#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
42#define _IO_BUFSIZ _G_BUFSIZ
43#define _IO_va_list _G_va_list
44
45#ifdef _G_NEED_STDARG_H
46/* This define avoids name pollution if we're using GNU stdarg.h */
40a55d20
UD
47# define __need___va_list
48# include <stdarg.h>
49# ifdef __GNUC_VA_LIST
50# undef _IO_va_list
51# define _IO_va_list __gnuc_va_list
52# endif /* __GNUC_VA_LIST */
96aa2d94
RM
53#endif
54
55#ifndef __P
40a55d20
UD
56# if _G_HAVE_SYS_CDEFS
57# include <sys/cdefs.h>
58# else
59# ifdef __STDC__
cc3fa755 60# define __P(p) p
fdacb17d 61# define __PMT(p) p
40a55d20 62# else
cc3fa755 63# define __P(p) ()
fdacb17d 64# define __PMT(p) ()
40a55d20
UD
65# endif
66# endif
96aa2d94
RM
67#endif /*!__P*/
68
69/* For backward compatibility */
70#ifndef _PARAMS
40a55d20 71# define _PARAMS(protos) __P(protos)
96aa2d94
RM
72#endif /*!_PARAMS*/
73
74#ifndef __STDC__
999b2f6b
UD
75# ifndef const
76# define const
77# endif
96aa2d94
RM
78#endif
79#define _IO_UNIFIED_JUMPTABLES 1
2604afb1
UD
80#ifndef _G_HAVE_PRINTF_FP
81# define _IO_USE_DTOA 1
82#endif
96aa2d94 83
96aa2d94 84#ifndef EOF
40a55d20 85# define EOF (-1)
96aa2d94
RM
86#endif
87#ifndef NULL
40a55d20 88# if defined __GNUG__ && \
f8b87ef0 89 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
40a55d20
UD
90# define NULL (__null)
91# else
92# if !defined(__cplusplus)
93# define NULL ((void*)0)
94# else
95# define NULL (0)
96# endif
97# endif
f65fd747 98#endif
96aa2d94
RM
99
100#define _IOS_INPUT 1
101#define _IOS_OUTPUT 2
102#define _IOS_ATEND 4
103#define _IOS_APPEND 8
104#define _IOS_TRUNC 16
105#define _IOS_NOCREATE 32
106#define _IOS_NOREPLACE 64
107#define _IOS_BIN 128
108
109/* Magic numbers and bits for the _flags field.
110 The magic numbers use the high-order bits of _flags;
2c6fe0bd 111 the remaining bits are available for variable flags.
96aa2d94
RM
112 Note: The magic numbers must all be negative if stdio
113 emulation is desired. */
114
115#define _IO_MAGIC 0xFBAD0000 /* Magic number */
116#define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
117#define _IO_MAGIC_MASK 0xFFFF0000
118#define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */
119#define _IO_UNBUFFERED 2
120#define _IO_NO_READS 4 /* Reading not allowed */
121#define _IO_NO_WRITES 8 /* Writing not allowd */
122#define _IO_EOF_SEEN 0x10
123#define _IO_ERR_SEEN 0x20
124#define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */
125#define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/
126#define _IO_IN_BACKUP 0x100
127#define _IO_LINE_BUF 0x200
128#define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */
129#define _IO_CURRENTLY_PUTTING 0x800
130#define _IO_IS_APPENDING 0x1000
131#define _IO_IS_FILEBUF 0x2000
f671aeab 132#define _IO_BAD_SEEN 0x4000
96aa2d94
RM
133
134/* These are "formatting flags" matching the iostream fmtflags enum values. */
135#define _IO_SKIPWS 01
136#define _IO_LEFT 02
137#define _IO_RIGHT 04
138#define _IO_INTERNAL 010
139#define _IO_DEC 020
140#define _IO_OCT 040
141#define _IO_HEX 0100
142#define _IO_SHOWBASE 0200
143#define _IO_SHOWPOINT 0400
144#define _IO_UPPERCASE 01000
145#define _IO_SHOWPOS 02000
146#define _IO_SCIENTIFIC 04000
147#define _IO_FIXED 010000
148#define _IO_UNITBUF 020000
149#define _IO_STDIO 040000
150#define _IO_DONT_CLOSE 0100000
f671aeab 151#define _IO_BOOLALPHA 0200000
96aa2d94
RM
152
153
154struct _IO_jump_t; struct _IO_FILE;
155
7c713e28
RM
156/* Handle lock. */
157#ifdef _IO_MTSAFE_IO
a2b08ee5
UD
158# if defined __GLIBC__ && __GLIBC__ >= 2
159# include <bits/stdio-lock.h>
160# else
161/*# include <comthread.h>*/
162# endif
7c713e28
RM
163#else
164typedef void _IO_lock_t;
165#endif
96aa2d94 166
96aa2d94
RM
167
168/* A streammarker remembers a position in a buffer. */
169
170struct _IO_marker {
171 struct _IO_marker *_next;
172 struct _IO_FILE *_sbuf;
173 /* If _pos >= 0
174 it points to _buf->Gbase()+_pos. FIXME comment */
175 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
176 int _pos;
177#if 0
178 void set_streampos(streampos sp) { _spos = sp; }
179 void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
180 public:
181 streammarker(streambuf *sb);
182 ~streammarker();
183 int saving() { return _spos == -2; }
184 int delta(streammarker&);
185 int delta();
186#endif
187};
188
189struct _IO_FILE {
190 int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
191#define _IO_file_flags _flags
192
193 /* The following pointers correspond to the C++ streambuf protocol. */
f65fd747 194 /* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
96aa2d94
RM
195 char* _IO_read_ptr; /* Current read pointer */
196 char* _IO_read_end; /* End of get area. */
197 char* _IO_read_base; /* Start of putback+get area. */
198 char* _IO_write_base; /* Start of put area. */
199 char* _IO_write_ptr; /* Current put pointer. */
200 char* _IO_write_end; /* End of put area. */
201 char* _IO_buf_base; /* Start of reserve area. */
202 char* _IO_buf_end; /* End of reserve area. */
203 /* The following fields are used to support backing up and undo. */
204 char *_IO_save_base; /* Pointer to start of non-current get area. */
205 char *_IO_backup_base; /* Pointer to first valid character of backup area */
206 char *_IO_save_end; /* Pointer to end of non-current get area. */
207
208 struct _IO_marker *_markers;
209
210 struct _IO_FILE *_chain;
211
96aa2d94
RM
212 int _fileno;
213 int _blksize;
1ea89a40 214 _IO_off_t _old_offset; /* This used to be _offset but it's too small. */
96aa2d94
RM
215
216#define __HAVE_COLUMN /* temporary */
217 /* 1+column number of pbase(); 0 is unknown. */
218 unsigned short _cur_column;
bd355af0 219 signed char _vtable_offset;
96aa2d94
RM
220 char _shortbuf[1];
221
222 /* char* _save_gptr; char* _save_egptr; */
223
7c713e28 224 _IO_lock_t *_lock;
bd355af0
UD
225#ifdef _IO_USE_OLD_IO_FILE
226};
227
228struct _IO_FILE_complete
229{
230 struct _IO_FILE _file;
231#endif
232#if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001
233 _IO_off64_t _offset;
00bc5db0 234 /* Make sure we don't get into trouble again. */
05f732b3 235 int _unused2[16];
bd355af0 236#endif
96aa2d94
RM
237};
238
239#ifndef __cplusplus
240typedef struct _IO_FILE _IO_FILE;
241#endif
242
bd355af0
UD
243struct _IO_FILE_plus;
244extern struct _IO_FILE_plus _IO_2_1_stdin_;
245extern struct _IO_FILE_plus _IO_2_1_stdout_;
246extern struct _IO_FILE_plus _IO_2_1_stderr_;
6973fc01
UD
247#ifndef _LIBC
248#define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_))
249#define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_))
250#define _IO_stderr ((_IO_FILE*)(&_IO_2_1_stderr_))
251#else
252extern _IO_FILE *_IO_stdin;
253extern _IO_FILE *_IO_stdout;
254extern _IO_FILE *_IO_stderr;
255#endif
96aa2d94 256
fa0bc87c 257
9d1efe33 258#ifdef _GNU_SOURCE
1228ed5c
UD
259/* Define the user-visible type, with user-friendly member names. */
260typedef struct
261{
fdacb17d
UD
262 _IO_ssize_t (*read) __PMT ((struct _IO_FILE *, void *, _IO_ssize_t));
263 _IO_ssize_t (*write) __PMT ((struct _IO_FILE *, const void *, _IO_ssize_t));
264 _IO_fpos_t (*seek) __PMT ((struct _IO_FILE *, _IO_off_t, int));
265 int (*close) __PMT ((struct _IO_FILE *));
1228ed5c
UD
266} _IO_cookie_io_functions_t;
267
fa0bc87c 268/* Special file type for fopencookie function. */
40a55d20
UD
269struct _IO_cookie_file
270{
fa0bc87c
RM
271 struct _IO_FILE file;
272 const void *vtable;
273 void *cookie;
274 _IO_cookie_io_functions_t io_functions;
275};
9d1efe33 276#endif
fa0bc87c
RM
277
278
96aa2d94
RM
279#ifdef __cplusplus
280extern "C" {
281#endif
282
40a55d20
UD
283extern int __underflow __P ((_IO_FILE *));
284extern int __uflow __P ((_IO_FILE *));
285extern int __overflow __P ((_IO_FILE *, int));
96aa2d94 286
7c713e28 287#define _IO_getc_unlocked(_fp) \
40a55d20
UD
288 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow (_fp) \
289 : *(unsigned char *) (_fp)->_IO_read_ptr++)
7c713e28 290#define _IO_peekc_unlocked(_fp) \
96aa2d94 291 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
40a55d20
UD
292 && __underflow (_fp) == EOF ? EOF \
293 : *(unsigned char *) (_fp)->_IO_read_ptr)
bfcd44c3 294#define _IO_putc_unlocked(_ch, _fp) \
96aa2d94 295 (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
40a55d20 296 ? __overflow (_fp, (unsigned char) (_ch)) \
bfcd44c3 297 : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
96aa2d94 298
7c713e28
RM
299#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
300#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
96aa2d94 301
d41c6f61
UD
302extern int _IO_getc __P ((_IO_FILE *__fp));
303extern int _IO_putc __P ((int __c, _IO_FILE *__fp));
304extern int _IO_feof __P ((_IO_FILE *__fp));
305extern int _IO_ferror __P ((_IO_FILE *__fp));
306
307extern int _IO_peekc_locked __P ((_IO_FILE *__fp));
308
96aa2d94
RM
309/* This one is for Emacs. */
310#define _IO_PENDING_OUTPUT_COUNT(_fp) \
311 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
312
7c713e28
RM
313extern void _IO_flockfile __P ((_IO_FILE *));
314extern void _IO_funlockfile __P ((_IO_FILE *));
d41c6f61 315extern int _IO_ftrylockfile __P ((_IO_FILE *));
7c713e28 316
a2b08ee5
UD
317#ifdef _IO_MTSAFE_IO
318# define _IO_peekc(_fp) _IO_peekc_locked (_fp)
319#else
320# define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
d41c6f61
UD
321# define _IO_flockfile(_fp) /**/
322# define _IO_funlockfile(_fp) /**/
323# define _IO_ftrylockfile(_fp) /**/
68dbb3a6
UD
324# define _IO_cleanup_region_start(_fct, _fp) /**/
325# define _IO_cleanup_region_end(_Doit) /**/
edf5b2d7 326#endif /* !_IO_MTSAFE_IO */
7c713e28 327
a6ff34d7
UD
328extern int _IO_vfscanf __P ((_IO_FILE * __restrict, const char * __restrict,
329 _IO_va_list, int *__restrict));
330extern int _IO_vfprintf __P ((_IO_FILE *__restrict, const char *__restrict,
331 _IO_va_list));
40a55d20
UD
332extern _IO_ssize_t _IO_padn __P ((_IO_FILE *, int, _IO_ssize_t));
333extern _IO_size_t _IO_sgetn __P ((_IO_FILE *, void *, _IO_size_t));
96aa2d94 334
dfd2257a
UD
335extern _IO_fpos64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int));
336extern _IO_fpos64_t _IO_seekpos __P ((_IO_FILE *, _IO_fpos64_t, int));
8a523922 337
40a55d20 338extern void _IO_free_backup_area __P ((_IO_FILE *));
96aa2d94
RM
339
340#ifdef __cplusplus
341}
342#endif
343
344#endif /* _IO_STDIO_H */