Project

General

Profile

Statistics
| Branch: | Revision:

scoutos / prex-0.9.0 / usr / include / stdio.h @ 03e9c04a

History | View | Annotate | Download (9.68 KB)

1 03e9c04a Brad Neuman
/*-
2
 * Copyright (c) 1990, 1993
3
 *        The Regents of the University of California.  All rights reserved.
4
 *
5
 * This code is derived from software contributed to Berkeley by
6
 * Chris Torek.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. Neither the name of the University nor the names of its contributors
17
 *    may be used to endorse or promote products derived from this software
18
 *    without specific prior written permission.
19
 *
20
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30
 * SUCH DAMAGE.
31
 *
32
 *        @(#)stdio.h        8.5 (Berkeley) 4/29/95
33
 */
34
35
#ifndef        _STDIO_H_
36
#define        _STDIO_H_
37
38
#include <sys/types.h>
39
#include <sys/cdefs.h>
40
41
#if !defined(_SIZE_T)
42
#define _SIZE_T
43
typedef        unsigned int        size_t;                /* size of something in bytes */
44
#endif
45
46
#include <machine/stdarg.h>
47
48
#ifndef        NULL
49
#if !defined(__cplusplus)
50
#define        NULL        ((void *)0)
51
#else
52
#define        NULL        0
53
#endif
54
#endif
55
56
typedef off_t fpos_t;
57
58
#define        _FSTDIO                        /* Define for new stdio with functions. */
59
60
/*
61
 * NB: to fit things in six character monocase externals, the stdio
62
 * code uses the prefix `__s' for stdio objects, typically followed
63
 * by a three-character attempt at a mnemonic.
64
 */
65
66
/* stdio buffers */
67
struct __sbuf {
68
        unsigned char *_base;
69
        int        _size;
70
};
71
72
/*
73
 * stdio state variables.
74
 *
75
 * The following always hold:
76
 *
77
 *        if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
78
 *                _lbfsize is -_bf._size, else _lbfsize is 0
79
 *        if _flags&__SRD, _w is 0
80
 *        if _flags&__SWR, _r is 0
81
 *
82
 * This ensures that the getc and putc macros (or inline functions) never
83
 * try to write or read from a file that is in `read' or `write' mode.
84
 * (Moreover, they can, and do, automatically switch from read mode to
85
 * write mode, and back, on "r+" and "w+" files.)
86
 *
87
 * _lbfsize is used only to make the inline line-buffered output stream
88
 * code as compact as possible.
89
 *
90
 * _ub, _up, and _ur are used when ungetc() pushes back more characters
91
 * than fit in the current _bf, or when ungetc() pushes back a character
92
 * that does not match the previous one in _bf.  When this happens,
93
 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
94
 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
95
 *
96
 * NB: see WARNING above before changing the layout of this structure!
97
 */
98
typedef        struct __sFILE {
99
        struct __sFILE *next;        /* file chain */
100
        unsigned char *_p;        /* current position in (some) buffer */
101
        int        _r;                /* read space left for getc() */
102
        int        _w;                /* write space left for putc() */
103
        short        _flags;                /* flags, below; this FILE is free if 0 */
104
        short        _file;                /* fileno, if Unix descriptor, else -1 */
105
        struct        __sbuf _bf;        /* the buffer (at least 1 byte, if !NULL) */
106
107
        /* separate buffer for long sequences of ungetc() */
108
        struct        __sbuf _ub;        /* ungetc buffer */
109
        unsigned char *_up;        /* saved _p when _p is doing ungetc data */
110
        int        _ur;                /* saved _r when _r is counting ungetc data */
111
112
        /* tricks to meet minimum requirements even when malloc() fails */
113
        unsigned char _ubuf[3];        /* guarantee an ungetc() buffer */
114
        unsigned char _nbuf[1];        /* guarantee a getc() buffer */
115
} FILE;
116
117
__BEGIN_DECLS
118
extern FILE __sF[];
119
__END_DECLS
120
121
#define        __SLBF        0x0001                /* line buffered */
122
#define        __SNBF        0x0002                /* unbuffered */
123
#define        __SRD        0x0004                /* OK to read */
124
#define        __SWR        0x0008                /* OK to write */
125
        /* RD and WR are never simultaneously asserted */
126
#define        __SRW        0x0010                /* open for reading & writing */
127
#define        __SEOF        0x0020                /* found EOF */
128
#define        __SERR        0x0040                /* found error */
129
#define        __SMBF        0x0080                /* _buf is from malloc */
130
#define        __SAPP        0x0100                /* fdopen()ed in append mode */
131
#define        __SSTR        0x0200                /* this is an sprintf/snprintf string */
132
133
/*
134
 * The following three definitions are for ANSI C, which took them
135
 * from System V, which brilliantly took internal interface macros and
136
 * made them official arguments to setvbuf(), without renaming them.
137
 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
138
 *
139
 * Although numbered as their counterparts above, the implementation
140
 * does not rely on this.
141
 */
142
#define        _IOFBF        0                /* setvbuf should set fully buffered */
143
#define        _IOLBF        1                /* setvbuf should set line buffered */
144
#define        _IONBF        2                /* setvbuf should set unbuffered */
145
146
#define        BUFSIZ        512                /* size of buffer used by setbuf */
147
#define        EOF        (-1)
148
149
/*
150
 * FOPEN_MAX is a minimum maximum, and is the number of streams that
151
 * stdio can provide without attempting to allocate further resources
152
 * (which could fail).  Do not use this for anything.
153
 */
154
                                /* must be == _POSIX_STREAM_MAX <limits.h> */
155
#define        FOPEN_MAX        16        /* must be <= OPEN_MAX <sys/syslimits.h> */
156
#define        FILENAME_MAX        256        /* must be <= PATH_MAX <sys/syslimits.h> */
157
158
/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
159
#ifndef _ANSI_SOURCE
160
#define        P_tmpdir        "/var/tmp/"
161
#endif
162
#define        L_tmpnam        255        /* XXX must be == PATH_MAX */
163
#define        TMP_MAX                308915776
164
165
/* access function */
166
#define        F_OK                0        /* test for existence of file */
167
#define        X_OK                0x01        /* test for execute or search permission */
168
#define        W_OK                0x02        /* test for write permission */
169
#define        R_OK                0x04        /* test for read permission */
170
171
/* whence values for lseek(2) */
172
#define        SEEK_SET        0        /* set file offset to offset */
173
#define        SEEK_CUR        1        /* set file offset to current plus offset */
174
#define        SEEK_END        2        /* set file offset to EOF plus offset */
175
176
#define        stdin        (&__sF[0])
177
#define        stdout        (&__sF[1])
178
#define        stderr        (&__sF[2])
179
180
/*
181
 * Functions defined in ANSI C standard.
182
 */
183
__BEGIN_DECLS
184
void         clearerr(FILE *);
185
int         fclose(FILE *);
186
int         feof(FILE *);
187
int         ferror(FILE *);
188
int         fflush(FILE *);
189
int         fgetc(FILE *);
190
int         fgetpos(FILE *, fpos_t *);
191
char        *fgets(char *, size_t, FILE *);
192
FILE        *fopen(const char *, const char *);
193
int         fprintf(FILE *, const char *, ...);
194
int         fputc(int, FILE *);
195
int         fputs(const char *, FILE *);
196
size_t         fread(void *, size_t, size_t, FILE *);
197
FILE        *freopen(const char *, const char *, FILE *);
198
int         fscanf(FILE *, const char *, ...);
199
int         fseek(FILE *, long, int);
200
int         fsetpos(FILE *, const fpos_t *);
201
long         ftell(FILE *);
202
size_t         fwrite(const void *, size_t, size_t, FILE *);
203
int         getc(FILE *);
204
int         getchar(void);
205
char        *gets(char *);
206
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
207
extern const int _sys_nerr;                        /* perror(3) external variables */
208
extern const char *const _sys_errlist[];
209
#endif
210
void         perror(const char *);
211
int         printf(const char *, ...);
212
int         putc(int, FILE *);
213
int         putchar(int);
214
int         puts(const char *);
215
int         remove(const char *);
216
int         rename (const char *, const char *);
217
void         rewind(FILE *);
218
int         scanf(const char *, ...);
219
void         setbuf(FILE *, char *);
220
int         setvbuf(FILE *, char *, int, size_t);
221
int         sprintf(char *, const char *, ...);
222
int         sscanf(const char *, const char *, ...);
223
FILE        *tmpfile(void);
224
char        *tmpnam(char *);
225
int         ungetc(int, FILE *);
226
int         vfprintf(FILE *, const char *, va_list);
227
int         vprintf(const char *, va_list);
228
int         vsprintf(char *, const char *, va_list);
229
__END_DECLS
230
231
/*
232
 * Functions defined in POSIX 1003.1.
233
 */
234
#ifndef _ANSI_SOURCE
235
#define        L_cuserid        9        /* size for cuserid(); UT_NAMESIZE + 1 */
236
#define        L_ctermid        1024        /* size for ctermid(); PATH_MAX */
237
238
__BEGIN_DECLS
239
char        *ctermid(char *);
240
FILE        *fdopen(int, const char *);
241
int         fileno(FILE *);
242
__END_DECLS
243
#endif /* not ANSI */
244
245
/*
246
 * Routines that are purely local.
247
 */
248
#if !defined (_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
249
__BEGIN_DECLS
250
int         fpurge(FILE *);
251
int         getw(FILE *);
252
int         pclose(FILE *);
253
FILE        *popen(const char *, const char *);
254
int         putw(int, FILE *);
255
void         setbuffer(FILE *, char *, int);
256
int         setlinebuf(FILE *);
257
char        *tempnam(const char *, const char *);
258
int         snprintf(char *, size_t, const char *, ...);
259
int         vsnprintf(char *, size_t, const char *, va_list);
260
int         vscanf(const char *, va_list);
261
int         vsscanf(const char *, const char *, va_list);
262
FILE        *zopen(const char *, const char *, int);
263
__END_DECLS
264
265
/*
266
 * This is a #define because the function is used internally and
267
 * (unlike vfscanf) the name __svfscanf is guaranteed not to collide
268
 * with a user function when _ANSI_SOURCE or _POSIX_SOURCE is defined.
269
 */
270
#define         vfscanf        __svfscanf
271
272
#endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
273
274
/*
275
 * Functions internal to the implementation.
276
 */
277
__BEGIN_DECLS
278
int        __srget(FILE *);
279
int        __svfscanf(FILE *, const char *, va_list);
280
int        __swbuf(int, FILE *);
281
__END_DECLS
282
283
/*
284
 * The __sfoo macros are here so that we can
285
 * define function versions in the C library.
286
 */
287
288
#define        __sfeof(p)        (((p)->_flags & __SEOF) != 0)
289
#define        __sferror(p)        (((p)->_flags & __SERR) != 0)
290
#define        __sclearerr(p)        ((void)((p)->_flags &= ~(__SERR|__SEOF)))
291
#define        __sfileno(p)        ((p)->_file)
292
293
#define        feof(p)                __sfeof(p)
294
#define        ferror(p)        __sferror(p)
295
#define        clearerr(p)        __sclearerr(p)
296
297
#ifndef _ANSI_SOURCE
298
#define        fileno(p)        __sfileno(p)
299
#endif
300
301
#endif /* _STDIO_H_ */