OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [include/] [stdio.h] - Blame information for rev 39

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/*
2
 * Copyright (c) 1990 The Regents of the University of California.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms are permitted
6
 * provided that the above copyright notice and this paragraph are
7
 * duplicated in all such forms and that any documentation,
8
 * advertising materials, and other materials related to such
9
 * distribution and use acknowledge that the software was developed
10
 * by the University of California, Berkeley.  The name of the
11
 * University may not be used to endorse or promote products derived
12
 * from this software without specific prior written permission.
13
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16
 *
17
 *      @(#)stdio.h     5.3 (Berkeley) 3/15/86
18
 */
19
 
20
/*
21
 * NB: to fit things in six character monocase externals, the
22
 * stdio code uses the prefix `__s' for stdio objects, typically
23
 * followed by a three-character attempt at a mnemonic.
24
 */
25
 
26
#ifndef _STDIO_H_
27
#ifdef __cplusplus
28
extern "C" {
29
#endif
30
#define _STDIO_H_
31
 
32
#include "_ansi.h"
33
 
34
#define _FSTDIO                 /* ``function stdio'' */
35
 
36
#define __need_size_t
37
#include <stddef.h>
38
 
39
#define __need___va_list
40
#include <stdarg.h>
41
 
42
/*
43
 * <sys/reent.h> defines __sFILE, _fpos_t.
44
 * They must be defined there because struct _reent needs them (and we don't
45
 * want reent.h to include this file.
46
 */
47
 
48
#include <sys/reent.h>
49
 
50
typedef _fpos_t fpos_t;
51
 
52
typedef struct __sFILE FILE;
53
 
54
#define __SLBF  0x0001          /* line buffered */
55
#define __SNBF  0x0002          /* unbuffered */
56
#define __SRD   0x0004          /* OK to read */
57
#define __SWR   0x0008          /* OK to write */
58
        /* RD and WR are never simultaneously asserted */
59
#define __SRW   0x0010          /* open for reading & writing */
60
#define __SEOF  0x0020          /* found EOF */
61
#define __SERR  0x0040          /* found error */
62
#define __SMBF  0x0080          /* _buf is from malloc */
63
#define __SAPP  0x0100          /* fdopen()ed in append mode - so must  write to end */
64
#define __SSTR  0x0200          /* this is an sprintf/snprintf string */
65
#define __SOPT  0x0400          /* do fseek() optimisation */
66
#define __SNPT  0x0800          /* do not do fseek() optimisation */
67
#define __SOFF  0x1000          /* set iff _offset is in fact correct */
68
#define __SMOD  0x2000          /* true => fgetline modified _p text */
69
 
70
/*
71
 * The following three definitions are for ANSI C, which took them
72
 * from System V, which stupidly took internal interface macros and
73
 * made them official arguments to setvbuf(), without renaming them.
74
 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
75
 *
76
 * Although these happen to match their counterparts above, the
77
 * implementation does not rely on that (so these could be renumbered).
78
 */
79
#define _IOFBF  0                /* setvbuf should set fully buffered */
80
#define _IOLBF  1               /* setvbuf should set line buffered */
81
#define _IONBF  2               /* setvbuf should set unbuffered */
82
 
83
#ifndef NULL
84
#define NULL    0L
85
#endif
86
 
87
#define BUFSIZ  1024
88
#define EOF     (-1)
89
 
90
#define FOPEN_MAX       20      /* must be <= OPEN_MAX <sys/syslimits.h> */
91
#define FILENAME_MAX    1024    /* must be <= PATH_MAX <sys/syslimits.h> */
92
#define L_tmpnam        1024    /* XXX must be == PATH_MAX */
93
#ifndef _STRICT_ANSI
94
#define P_tmpdir        "/tmp"
95
#endif
96
 
97
#ifndef SEEK_SET
98
#define SEEK_SET        0        /* set file offset to offset */
99
#endif
100
#ifndef SEEK_CUR
101
#define SEEK_CUR        1       /* set file offset to current plus offset */
102
#endif
103
#ifndef SEEK_END
104
#define SEEK_END        2       /* set file offset to EOF plus offset */
105
#endif
106
 
107
#define TMP_MAX         26
108
 
109
#define stdin   (_impure_ptr->_stdin)
110
#define stdout  (_impure_ptr->_stdout)
111
#define stderr  (_impure_ptr->_stderr)
112
 
113
#define _stdin_r(x)     ((x)->_stdin)
114
#define _stdout_r(x)    ((x)->_stdout)
115
#define _stderr_r(x)    ((x)->_stderr)
116
 
117
/*
118
 * Functions defined in ANSI C standard.
119
 */
120
 
121
#ifdef __GNUC__
122
#define __VALIST __gnuc_va_list
123
#else
124
#define __VALIST char*
125
#endif
126
 
127
#ifndef _REENT_ONLY
128
int     _EXFUN(remove, (const char *));
129
int     _EXFUN(rename, (const char *, const char *));
130
#endif
131
FILE *  _EXFUN(tmpfile, (void));
132
char *  _EXFUN(tmpnam, (char *));
133
int     _EXFUN(fclose, (FILE *));
134
int     _EXFUN(fflush, (FILE *));
135
FILE *  _EXFUN(freopen, (const char *, const char *, FILE *));
136
void    _EXFUN(setbuf, (FILE *, char *));
137
int     _EXFUN(setvbuf, (FILE *, char *, int, size_t));
138
int     _EXFUN(fprintf, (FILE *, const char *, ...));
139
int     _EXFUN(fscanf, (FILE *, const char *, ...));
140
int     _EXFUN(printf, (const char *, ...));
141
int     _EXFUN(scanf, (const char *, ...));
142
int     _EXFUN(sscanf, (const char *, const char *, ...));
143
int     _EXFUN(vfprintf, (FILE *, const char *, __VALIST));
144
int     _EXFUN(vprintf, (const char *, __VALIST));
145
int     _EXFUN(vsprintf, (char *, const char *, __VALIST));
146
int     _EXFUN(fgetc, (FILE *));
147
char *  _EXFUN(fgets, (char *, int, FILE *));
148
int     _EXFUN(fputc, (int, FILE *));
149
int     _EXFUN(fputs, (const char *, FILE *));
150
int     _EXFUN(getc, (FILE *));
151
int     _EXFUN(getchar, (void));
152
char *  _EXFUN(gets, (char *));
153
int     _EXFUN(putc, (int, FILE *));
154
int     _EXFUN(putchar, (int));
155
int     _EXFUN(puts, (const char *));
156
int     _EXFUN(ungetc, (int, FILE *));
157
size_t  _EXFUN(fread, (_PTR, size_t _size, size_t _n, FILE *));
158
size_t  _EXFUN(fwrite, (const _PTR , size_t _size, size_t _n, FILE *));
159
int     _EXFUN(fgetpos, (FILE *, fpos_t *));
160
int     _EXFUN(fseek, (FILE *, long, int));
161
int     _EXFUN(fsetpos, (FILE *, const fpos_t *));
162
long    _EXFUN(ftell, ( FILE *));
163
void    _EXFUN(rewind, (FILE *));
164
void    _EXFUN(clearerr, (FILE *));
165
int     _EXFUN(feof, (FILE *));
166
int     _EXFUN(ferror, (FILE *));
167
void    _EXFUN(perror, (const char *));
168
#ifndef _REENT_ONLY
169
FILE *  _EXFUN(fopen, (const char *_name, const char *_type));
170
int     _EXFUN(sprintf, (char *, const char *, ...));
171
#endif
172
#ifndef _STRICT_ANSI
173
int     _EXFUN(vfiprintf, (FILE *, const char *, __VALIST));
174
int     _EXFUN(iprintf, (const char *, ...));
175
int     _EXFUN(fiprintf, (FILE *, const char *, ...));
176
int     _EXFUN(siprintf, (char *, const char *, ...));
177
#endif
178
 
179
/*
180
 * Routines in POSIX 1003.1.
181
 */
182
 
183
#ifndef _STRICT_ANSI
184
#ifndef _REENT_ONLY
185
FILE *  _EXFUN(fdopen, (int, const char *));
186
#endif
187
int     _EXFUN(fileno, (FILE *));
188
int     _EXFUN(getw, (FILE *));
189
int     _EXFUN(pclose, (FILE *));
190
FILE *  _EXFUN(popen, (const char *, const char *));
191
int     _EXFUN(putw, (int, FILE *));
192
void    _EXFUN(setbuffer, (FILE *, char *, int));
193
int     _EXFUN(setlinebuf, (FILE *));
194
#endif
195
 
196
/*
197
 * Recursive versions of the above.
198
 */
199
 
200
FILE *  _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
201
FILE *  _EXFUN(_fopen_r, (struct _reent *, const char *, const char *));
202
int     _EXFUN(_getchar_r, (struct _reent *));
203
char *  _EXFUN(_gets_r, (struct _reent *, char *));
204
int     _EXFUN(_iprintf_r, (struct _reent *, const char *, ...));
205
int     _EXFUN(_mkstemp_r, (struct _reent *, char *));
206
char *  _EXFUN(_mktemp_r, (struct _reent *, char *));
207
void    _EXFUN(_perror_r, (struct _reent *, const char *));
208
int     _EXFUN(_printf_r, (struct _reent *, const char *, ...));
209
int     _EXFUN(_putchar_r, (struct _reent *, int));
210
int     _EXFUN(_puts_r, (struct _reent *, const char *));
211
int     _EXFUN(_remove_r, (struct _reent *, const char *));
212
int     _EXFUN(_rename_r, (struct _reent *,
213
                           const char *_old, const char *_new));
214
int     _EXFUN(_scanf_r, (struct _reent *, const char *, ...));
215
int     _EXFUN(_sprintf_r, (struct _reent *, char *, const char *, ...));
216
char *  _EXFUN(_tempnam_r, (struct _reent *, char *, char *));
217
FILE *  _EXFUN(_tmpfile_r, (struct _reent *));
218
char *  _EXFUN(_tmpnam_r, (struct _reent *, char *));
219
int     _EXFUN(_vfprintf_r, (struct _reent *, FILE *, const char *, __VALIST));
220
int     _EXFUN(_vprintf_r, (struct _reent *, const char *, __VALIST));
221
int     _EXFUN(_vsprintf_r, (struct _reent *, char *, const char *, __VALIST));
222
 
223
/*
224
 * Routines internal to the implementation.
225
 */
226
 
227
int     _EXFUN(__srget, (FILE *));
228
int     _EXFUN(__swbuf, (int, FILE *));
229
 
230
/*
231
 * Stdio function-access interface.
232
 */
233
 
234
#ifndef _STRICT_ANSI
235
FILE    *_EXFUN(funopen,(const _PTR _cookie,
236
                int (*readfn)(_PTR _cookie, char *_buf, int _n),
237
                int (*writefn)(_PTR _cookie, const char *_buf, int _n),
238
                fpos_t (*seekfn)(_PTR _cookie, fpos_t _off, int _whence),
239
                int (*closefn)(_PTR _cookie)));
240
 
241
#define fropen(cookie, fn) funopen(cookie, fn, (int (*)())0, (fpos_t (*)())0, (int (*)())0)
242
#define fwopen(cookie, fn) funopen(cookie, (int (*)())0, fn, (fpos_t (*)())0, (int (*)())0)
243
#endif
244
 
245
/*
246
 * The __sfoo macros are here so that we can
247
 * define function versions in the C library.
248
 */
249
#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
250
#ifdef _never /* __GNUC__ */
251
/* If this inline is actually used, then systems using coff debugging
252
   info get hopelessly confused.  21sept93 rich@cygnus.com.  */
253
static __inline int __sputc(int _c, FILE *_p) {
254
        if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
255
                return (*_p->_p++ = _c);
256
        else
257
                return (__swbuf(_c, _p));
258
}
259
#else
260
/*
261
 * This has been tuned to generate reasonable code on the vax using pcc
262
 */
263
#define __sputc(c, p) \
264
        (--(p)->_w < 0 ? \
265
                (p)->_w >= (p)->_lbfsize ? \
266
                        (*(p)->_p = (c)), *(p)->_p != '\n' ? \
267
                                (int)*(p)->_p++ : \
268
                                __swbuf('\n', p) : \
269
                        __swbuf((int)(c), p) : \
270
                (*(p)->_p = (c), (int)*(p)->_p++))
271
#endif
272
 
273
#define __sfeof(p)      (((p)->_flags & __SEOF) != 0)
274
#define __sferror(p)    (((p)->_flags & __SERR) != 0)
275
#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
276
#define __sfileno(p)    ((p)->_file)
277
 
278
#define feof(p)         __sfeof(p)
279
#define ferror(p)       __sferror(p)
280
#define clearerr(p)     __sclearerr(p)
281
 
282
#if 0 /*ndef _STRICT_ANSI - FIXME: must initialize stdio first, use fn */
283
#define fileno(p)       __sfileno(p)
284
#endif
285
 
286
#ifndef lint
287
#define getc(fp)        __sgetc(fp)
288
#define putc(x, fp)     __sputc(x, fp)
289
#endif /* lint */
290
 
291
#define getchar()       getc(stdin)
292
#define putchar(x)      putc(x, stdout)
293
 
294
#ifndef _STRICT_ANSI
295
/* fast always-buffered version, true iff error */
296
#define fast_putc(x,p) (--(p)->_w < 0 ? \
297
        __swbuf((int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
298
 
299
#define L_cuserid       9               /* posix says it goes in stdio.h :( */
300
#ifdef __CYGWIN32__
301
#define L_ctermid       16
302
#endif
303
#endif
304
 
305
#ifdef __cplusplus
306
}
307
#endif
308
#endif /* _STDIO_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.