]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/libio.h
update from main archive 970129
[thirdparty/glibc.git] / libio / libio.h
CommitLineData
96aa2d94
RM
1/*
2Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation
3
4This file is part of the GNU IO Library. This library is free
5software; you can redistribute it and/or modify it under the
6terms of the GNU General Public License as published by the
7Free Software Foundation; either version 2, or (at your option)
8any later version.
9
10This library is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this library; see the file COPYING. If not, write to the Free
17Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19As a special exception, if you link this library with files
20compiled with a GNU compiler to produce an executable, this does not cause
21the resulting executable to be covered by the GNU General Public License.
22This exception does not however invalidate any other reasons why
23the executable file might be covered by the GNU General Public License. */
24
25/* This is part of the iostream library. Written by Per Bothner. */
26
27#ifndef _IO_STDIO_H
28#define _IO_STDIO_H
d41c6f61 29#include <features.h>
96aa2d94
RM
30
31#include <_G_config.h>
32#define _IO_pos_t _G_fpos_t /* obsolete */
33#define _IO_fpos_t _G_fpos_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_pid_t _G_pid_t
38#define _IO_uid_t _G_uid_t
39#define _IO_HAVE_SYS_WAIT _G_HAVE_SYS_WAIT
40#define _IO_HAVE_ST_BLKSIZE _G_HAVE_ST_BLKSIZE
41#define _IO_BUFSIZ _G_BUFSIZ
42#define _IO_va_list _G_va_list
43
44#ifdef _G_NEED_STDARG_H
45/* This define avoids name pollution if we're using GNU stdarg.h */
46#define __need___va_list
47#include <stdarg.h>
48#ifdef __GNUC_VA_LIST
49#undef _IO_va_list
50#define _IO_va_list __gnuc_va_list
51#endif /* __GNUC_VA_LIST */
52#endif
53
54#ifndef __P
f65fd747
UD
55#if _G_HAVE_SYS_CDEFS
56#include <sys/cdefs.h>
57#else
96aa2d94
RM
58#ifdef __STDC__
59#define __P(protos) protos
60#else
61#define __P(protos) ()
62#endif
f65fd747 63#endif
96aa2d94
RM
64#endif /*!__P*/
65
66/* For backward compatibility */
67#ifndef _PARAMS
68#define _PARAMS(protos) __P(protos)
69#endif /*!_PARAMS*/
70
71#ifndef __STDC__
72#define const
73#endif
74#define _IO_UNIFIED_JUMPTABLES 1
75
76#if 0
77#ifdef _IO_NEED_STDARG_H
78#include <stdarg.h>
79#endif
80#endif
81
82#ifndef EOF
83#define EOF (-1)
84#endif
85#ifndef NULL
f8b87ef0
UD
86#if defined __GNUG__ && \
87 (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
f65fd747
UD
88#define NULL (__null)
89#else
90#if !defined(__cplusplus)
96aa2d94
RM
91#define NULL ((void*)0)
92#else
93#define NULL (0)
94#endif
95#endif
f65fd747 96#endif
96aa2d94
RM
97
98#define _IOS_INPUT 1
99#define _IOS_OUTPUT 2
100#define _IOS_ATEND 4
101#define _IOS_APPEND 8
102#define _IOS_TRUNC 16
103#define _IOS_NOCREATE 32
104#define _IOS_NOREPLACE 64
105#define _IOS_BIN 128
106
107/* Magic numbers and bits for the _flags field.
108 The magic numbers use the high-order bits of _flags;
2c6fe0bd 109 the remaining bits are available for variable flags.
96aa2d94
RM
110 Note: The magic numbers must all be negative if stdio
111 emulation is desired. */
112
113#define _IO_MAGIC 0xFBAD0000 /* Magic number */
114#define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
115#define _IO_MAGIC_MASK 0xFFFF0000
116#define _IO_USER_BUF 1 /* User owns buffer; don't delete it on close. */
117#define _IO_UNBUFFERED 2
118#define _IO_NO_READS 4 /* Reading not allowed */
119#define _IO_NO_WRITES 8 /* Writing not allowd */
120#define _IO_EOF_SEEN 0x10
121#define _IO_ERR_SEEN 0x20
122#define _IO_DELETE_DONT_CLOSE 0x40 /* Don't call close(_fileno) on cleanup. */
123#define _IO_LINKED 0x80 /* Set if linked (using _chain) to streambuf::_list_all.*/
124#define _IO_IN_BACKUP 0x100
125#define _IO_LINE_BUF 0x200
126#define _IO_TIED_PUT_GET 0x400 /* Set if put and get pointer logicly tied. */
127#define _IO_CURRENTLY_PUTTING 0x800
128#define _IO_IS_APPENDING 0x1000
129#define _IO_IS_FILEBUF 0x2000
130
131/* These are "formatting flags" matching the iostream fmtflags enum values. */
132#define _IO_SKIPWS 01
133#define _IO_LEFT 02
134#define _IO_RIGHT 04
135#define _IO_INTERNAL 010
136#define _IO_DEC 020
137#define _IO_OCT 040
138#define _IO_HEX 0100
139#define _IO_SHOWBASE 0200
140#define _IO_SHOWPOINT 0400
141#define _IO_UPPERCASE 01000
142#define _IO_SHOWPOS 02000
143#define _IO_SCIENTIFIC 04000
144#define _IO_FIXED 010000
145#define _IO_UNITBUF 020000
146#define _IO_STDIO 040000
147#define _IO_DONT_CLOSE 0100000
148
149
150struct _IO_jump_t; struct _IO_FILE;
151
152/* Define the user-visible type, with user-friendly member names. */
153typedef struct
154{
155 _IO_ssize_t (*read) __P ((struct _IO_FILE *, void *, _IO_ssize_t));
156 _IO_ssize_t (*write) __P ((struct _IO_FILE *, const void *, _IO_ssize_t));
157 _IO_fpos_t (*seek) __P ((struct _IO_FILE *, _IO_off_t, int));
158 int (*close) __P ((struct _IO_FILE *));
159} _IO_cookie_io_functions_t;
160
7c713e28
RM
161/* Handle lock. */
162#ifdef _IO_MTSAFE_IO
fafaa44e 163#include <stdio-lock.h>
7c713e28
RM
164#else
165typedef void _IO_lock_t;
166#endif
96aa2d94 167
96aa2d94
RM
168
169/* A streammarker remembers a position in a buffer. */
170
171struct _IO_marker {
172 struct _IO_marker *_next;
173 struct _IO_FILE *_sbuf;
174 /* If _pos >= 0
175 it points to _buf->Gbase()+_pos. FIXME comment */
176 /* if _pos < 0, it points to _buf->eBptr()+_pos. FIXME comment */
177 int _pos;
178#if 0
179 void set_streampos(streampos sp) { _spos = sp; }
180 void set_offset(int offset) { _pos = offset; _spos = (streampos)(-2); }
181 public:
182 streammarker(streambuf *sb);
183 ~streammarker();
184 int saving() { return _spos == -2; }
185 int delta(streammarker&);
186 int delta();
187#endif
188};
189
190struct _IO_FILE {
191 int _flags; /* High-order word is _IO_MAGIC; rest is flags. */
192#define _IO_file_flags _flags
193
194 /* The following pointers correspond to the C++ streambuf protocol. */
f65fd747 195 /* Note: Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
96aa2d94
RM
196 char* _IO_read_ptr; /* Current read pointer */
197 char* _IO_read_end; /* End of get area. */
198 char* _IO_read_base; /* Start of putback+get area. */
199 char* _IO_write_base; /* Start of put area. */
200 char* _IO_write_ptr; /* Current put pointer. */
201 char* _IO_write_end; /* End of put area. */
202 char* _IO_buf_base; /* Start of reserve area. */
203 char* _IO_buf_end; /* End of reserve area. */
204 /* The following fields are used to support backing up and undo. */
205 char *_IO_save_base; /* Pointer to start of non-current get area. */
206 char *_IO_backup_base; /* Pointer to first valid character of backup area */
207 char *_IO_save_end; /* Pointer to end of non-current get area. */
208
209 struct _IO_marker *_markers;
210
211 struct _IO_FILE *_chain;
212
96aa2d94
RM
213 int _fileno;
214 int _blksize;
215 _IO_off_t _offset;
216
217#define __HAVE_COLUMN /* temporary */
218 /* 1+column number of pbase(); 0 is unknown. */
219 unsigned short _cur_column;
220 char _unused;
221 char _shortbuf[1];
222
223 /* char* _save_gptr; char* _save_egptr; */
224
7c713e28 225 _IO_lock_t *_lock;
96aa2d94
RM
226};
227
228#ifndef __cplusplus
229typedef struct _IO_FILE _IO_FILE;
230#endif
231
232struct _IO_FILE_plus;
233extern struct _IO_FILE_plus _IO_stdin_, _IO_stdout_, _IO_stderr_;
234#define _IO_stdin ((_IO_FILE*)(&_IO_stdin_))
235#define _IO_stdout ((_IO_FILE*)(&_IO_stdout_))
236#define _IO_stderr ((_IO_FILE*)(&_IO_stderr_))
237
fa0bc87c
RM
238
239/* Special file type for fopencookie function. */
240struct _IO_cookie_file {
241 struct _IO_FILE file;
242 const void *vtable;
243 void *cookie;
244 _IO_cookie_io_functions_t io_functions;
245};
246
247
96aa2d94
RM
248#ifdef __cplusplus
249extern "C" {
250#endif
251
252extern int __underflow __P((_IO_FILE*));
253extern int __uflow __P((_IO_FILE*));
254extern int __overflow __P((_IO_FILE*, int));
255
7c713e28 256#define _IO_getc_unlocked(_fp) \
96aa2d94
RM
257 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow(_fp) \
258 : *(unsigned char*)(_fp)->_IO_read_ptr++)
7c713e28 259#define _IO_peekc_unlocked(_fp) \
96aa2d94
RM
260 ((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
261 && __underflow(_fp) == EOF ? EOF \
262 : *(unsigned char*)(_fp)->_IO_read_ptr)
263
7c713e28 264#define _IO_putc_unlocked(_ch, _fp) \
96aa2d94
RM
265 (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
266 ? __overflow(_fp, (unsigned char)(_ch)) \
267 : (unsigned char)(*(_fp)->_IO_write_ptr++ = (_ch)))
268
7c713e28
RM
269#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
270#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
96aa2d94 271
d41c6f61
UD
272extern int _IO_getc __P ((_IO_FILE *__fp));
273extern int _IO_putc __P ((int __c, _IO_FILE *__fp));
274extern int _IO_feof __P ((_IO_FILE *__fp));
275extern int _IO_ferror __P ((_IO_FILE *__fp));
276
277extern int _IO_peekc_locked __P ((_IO_FILE *__fp));
278
96aa2d94
RM
279/* This one is for Emacs. */
280#define _IO_PENDING_OUTPUT_COUNT(_fp) \
281 ((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
282
7c713e28
RM
283extern void _IO_flockfile __P ((_IO_FILE *));
284extern void _IO_funlockfile __P ((_IO_FILE *));
d41c6f61 285extern int _IO_ftrylockfile __P ((_IO_FILE *));
7c713e28 286
ba1ffaa1 287#ifndef _IO_MTSAFE_IO
d41c6f61
UD
288# define _IO_flockfile(_fp) /**/
289# define _IO_funlockfile(_fp) /**/
290# define _IO_ftrylockfile(_fp) /**/
68dbb3a6
UD
291# define _IO_cleanup_region_start(_fct, _fp) /**/
292# define _IO_cleanup_region_end(_Doit) /**/
edf5b2d7 293#endif /* !_IO_MTSAFE_IO */
7c713e28 294
19361cb7
UD
295/* XXX Should we allow a symbol to be defined which selects the efficient
296 implementation when the user is really sure no threaded functions ever
297 will be used? */
298#if 1
d41c6f61
UD
299# define _IO_getc(_fp) _IO_getc (_fp)
300# define _IO_peekc(_fp) _IO_peekc_locked (_fp)
301# define _IO_putc(_ch, _fp) _IO_putc (_ch, _fp)
302# define _IO_feof(_fp) _IO_feof (_fp)
303# define _IO_ferror(_fp) _IO_ferror (_fp)
304#else
305# define _IO_getc(_fp) _IO_getc_unlocked (_fp)
306# define _IO_peekc(_fp) _IO_peekc_unlocked (_fp)
307# define _IO_putc(_ch, _fp) _IO_putc_unlocked (_ch, _fp)
308# define _IO_feof(_fp) _IO_feof_unlocked (_fp)
309# define _IO_ferror(_fp) _IO_ferror_unlocked (_fp)
310#endif
7c713e28 311
96aa2d94
RM
312extern int _IO_vfscanf __P((_IO_FILE*, const char*, _IO_va_list, int*));
313extern int _IO_vfprintf __P((_IO_FILE*, const char*, _IO_va_list));
314extern _IO_ssize_t _IO_padn __P((_IO_FILE *, int, _IO_ssize_t));
315extern _IO_size_t _IO_sgetn __P((_IO_FILE *, void*, _IO_size_t));
316
8a523922
UD
317extern _IO_fpos_t _IO_seekoff __P((_IO_FILE*, _IO_off_t, int, int));
318extern _IO_fpos_t _IO_seekpos __P((_IO_FILE*, _IO_fpos_t, int));
319
96aa2d94
RM
320extern void _IO_free_backup_area __P((_IO_FILE*));
321
322#ifdef __cplusplus
323}
324#endif
325
326#endif /* _IO_STDIO_H */