source: trunk/src/emx/include/stdio.h@ 1015

Last change on this file since 1015 was 881, checked in by bird, 22 years ago

Increased buffer size of 2 pages.

  • Property cvs2svn:cvs-rev set to 1.9
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 17.9 KB
Line 
1/*-
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. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)stdio.h 8.5 (Berkeley) 4/29/95
37 * $FreeBSD: src/include/stdio.h,v 1.51 2003/01/13 08:41:47 tjr Exp $
38 */
39
40/** @file
41 * FreeBSD 5.1
42 * @changed bird: EMX isms + LIBC implementation specifics.
43 * @chagned bird: Made quite a few @todos on function which aren't implemented.
44 */
45
46#ifndef _STDIO_H_
47#define _STDIO_H_
48
49#include <sys/cdefs.h>
50#include <sys/_types.h>
51
52typedef __off_t fpos_t;
53
54#if !defined(_SIZE_T_DECLARED) && !defined(_SIZE_T) /* bird: emx */
55typedef __size_t size_t;
56#define _SIZE_T_DECLARED
57#define _SIZE_T /* bird: emx */
58#endif
59
60#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
61#if !defined(_VA_LIST_DECLARED) && !defined(_VA_LIST) /* bird: emx */
62typedef __va_list va_list;
63#define _VA_LIST_DECLARED
64#define _VA_LIST /* bird: emx */
65#endif
66#endif
67
68#ifndef NULL
69#define NULL 0
70#endif
71
72#if 0 /* bird: emx */
73
74#define _FSTDIO /* Define for new stdio with functions. */
75
76
77/*
78 * NB: to fit things in six character monocase externals, the stdio
79 * code uses the prefix `__s' for stdio objects, typically followed
80 * by a three-character attempt at a mnemonic.
81 */
82
83/* stdio buffers */
84struct __sbuf {
85 unsigned char *_base;
86 int _size;
87};
88
89/* hold a buncha junk that would grow the ABI */
90struct __sFILEX;
91
92/*
93 * stdio state variables.
94 *
95 * The following always hold:
96 *
97 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
98 * _lbfsize is -_bf._size, else _lbfsize is 0
99 * if _flags&__SRD, _w is 0
100 * if _flags&__SWR, _r is 0
101 *
102 * This ensures that the getc and putc macros (or inline functions) never
103 * try to write or read from a file that is in `read' or `write' mode.
104 * (Moreover, they can, and do, automatically switch from read mode to
105 * write mode, and back, on "r+" and "w+" files.)
106 *
107 * _lbfsize is used only to make the inline line-buffered output stream
108 * code as compact as possible.
109 *
110 * _ub, _up, and _ur are used when ungetc() pushes back more characters
111 * than fit in the current _bf, or when ungetc() pushes back a character
112 * that does not match the previous one in _bf. When this happens,
113 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
114 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
115 *
116 * NB: see WARNING above before changing the layout of this structure!
117 */
118typedef struct __sFILE {
119 unsigned char *_p; /* current position in (some) buffer */
120 int _r; /* read space left for getc() */
121 int _w; /* write space left for putc() */
122 short _flags; /* flags, below; this FILE is free if 0 */
123 short _file; /* fileno, if Unix descriptor, else -1 */
124 struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
125 int _lbfsize; /* 0 or -_bf._size, for inline putc */
126
127 /* operations */
128 void *_cookie; /* cookie passed to io functions */
129 int (*_close)(void *);
130 int (*_read)(void *, char *, int);
131 fpos_t (*_seek)(void *, fpos_t, int);
132 int (*_write)(void *, const char *, int);
133
134 /* separate buffer for long sequences of ungetc() */
135 struct __sbuf _ub; /* ungetc buffer */
136 struct __sFILEX *_extra; /* additions to FILE to not break ABI */
137 int _ur; /* saved _r when _r is counting ungetc data */
138
139 /* tricks to meet minimum requirements even when malloc() fails */
140 unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
141 unsigned char _nbuf[1]; /* guarantee a getc() buffer */
142
143 /* separate buffer for fgetln() when line crosses buffer boundary */
144 struct __sbuf _lb; /* buffer for fgetln() */
145
146 /* Unix stdio files get aligned to block boundaries on fseek() */
147 int _blksize; /* stat.st_blksize (may be != _bf._size) */
148 fpos_t _offset; /* current lseek offset (see WARNING) */
149} FILE;
150
151__BEGIN_DECLS
152extern FILE *__stdinp;
153extern FILE *__stdoutp;
154extern FILE *__stderrp;
155__END_DECLS
156
157#define __SLBF 0x0001 /* line buffered */
158#define __SNBF 0x0002 /* unbuffered */
159#define __SRD 0x0004 /* OK to read */
160#define __SWR 0x0008 /* OK to write */
161 /* RD and WR are never simultaneously asserted */
162#define __SRW 0x0010 /* open for reading & writing */
163#define __SEOF 0x0020 /* found EOF */
164#define __SERR 0x0040 /* found error */
165#define __SMBF 0x0080 /* _buf is from malloc */
166#define __SAPP 0x0100 /* fdopen()ed in append mode */
167#define __SSTR 0x0200 /* this is an sprintf/snprintf string */
168#define __SOPT 0x0400 /* do fseek() optimization */
169#define __SNPT 0x0800 /* do not do fseek() optimization */
170#define __SOFF 0x1000 /* set iff _offset is in fact correct */
171#define __SMOD 0x2000 /* true => fgetln modified _p text */
172#define __SALC 0x4000 /* allocate string space dynamically */
173#define __SIGN 0x8000 /* ignore this file in _fwalk */
174
175#else /* bird: EMX specific FILE stuff starts. */
176
177#define _FILE_T
178#define _FILE_MEMBERS_HAVE_UNDERSCORE
179struct _file2;
180typedef struct _FILE
181{
182 char * _ptr;
183 char * _buffer;
184 int _rcount;
185 int _wcount;
186 int _handle;
187 int _flags;
188 int _buf_size;
189 int _tmpidx;
190 int _pid;
191 char _char_buf;
192 unsigned char _ungetc_count;
193 short _mbstate;
194 int (*_flush)(struct _FILE *, int);
195 struct _file2 *_more;
196} FILE;
197
198__BEGIN_DECLS
199extern FILE *__stdinp;
200extern FILE *__stdoutp;
201extern FILE *__stderrp;
202__END_DECLS
203
204#endif /* bird: EMX specific FILE stuff ends. */
205
206
207/*
208 * The following three definitions are for ANSI C, which took them
209 * from System V, which brilliantly took internal interface macros and
210 * made them official arguments to setvbuf(), without renaming them.
211 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
212 *
213 * Although numbered as their counterparts above, the implementation
214 * does not rely on this.
215 */
216#define _IOFBF 0 /* setvbuf should set fully buffered */
217#define _IOLBF 0x20 /* bird: emx, was 1 */ /* setvbuf should set line buffered */
218#define _IONBF 0x40 /* bird: emx, was 2 */ /* setvbuf should set unbuffered */
219
220#define BUFSIZ 8192 /* bird: emx, was 1024 */ /* size of buffer used by setbuf */
221#define EOF (-1)
222
223/*
224 * FOPEN_MAX is a minimum maximum, and is the number of streams that
225 * stdio can provide without attempting to allocate further resources
226 * (which could fail). Do not use this for anything.
227 */
228 /* must be == _POSIX_STREAM_MAX <limits.h> */
229#define FOPEN_MAX 14 /* bird: emx, was 20 */ /* must be <= OPEN_MAX <sys/syslimits.h> */
230#define FILENAME_MAX 260 /* bird: emx, was 1024 */ /* must be <= PATH_MAX <sys/syslimits.h> */
231
232/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
233#if __XSI_VISIBLE
234#define P_tmpdir "." /* bird: emx, was "/var/tmp/" */
235#endif
236#define L_tmpnam 260 /* bird: emx, was 1024 */ /* XXX must be == PATH_MAX */
237#define TMP_MAX 1000 /* bird: emx, was 308915776 */
238
239#ifndef SEEK_SET
240#define SEEK_SET 0 /* set file offset to offset */
241#endif
242#ifndef SEEK_CUR
243#define SEEK_CUR 1 /* set file offset to current plus offset */
244#endif
245#ifndef SEEK_END
246#define SEEK_END 2 /* set file offset to EOF plus offset */
247#endif
248
249#define stdin __stdinp
250#define stdout __stdoutp
251#define stderr __stderrp
252
253__BEGIN_DECLS
254/*
255 * Functions defined in ANSI C standard.
256 */
257void clearerr(FILE *);
258int fclose(FILE *);
259int feof(FILE *);
260int ferror(FILE *);
261int fflush(FILE *);
262int fgetc(FILE *);
263int fgetpos(FILE * __restrict, fpos_t * __restrict);
264char *fgets(char * __restrict, int, FILE * __restrict);
265FILE *fopen(const char * __restrict, const char * __restrict);
266int fprintf(FILE * __restrict, const char * __restrict, ...);
267int fputc(int, FILE *);
268int fputs(const char * __restrict, FILE * __restrict);
269size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
270FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict);
271int fscanf(FILE * __restrict, const char * __restrict, ...);
272int fseek(FILE *, long, int);
273int fsetpos(FILE *, const fpos_t *);
274long ftell(FILE *);
275size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
276#if 0 /* bird: emx */
277int getc(FILE *);
278#else /* bird: emx */
279/** @todo: Check the standard, if this is correct or not. declaration might be required. */
280#define getc(s) fgetc(s) /* bird: emx */
281#endif /* bird: emx */
282int getchar(void);
283char *gets(char *);
284void perror(const char *);
285int printf(const char * __restrict, ...);
286#if 0 /* bird: emx */
287int putc(int, FILE *);
288#else /* bird: emx */
289/** @todo: Check the standard, if this is correct or not. declaration might be required. */
290#define putc(c,s) fputc(c,s) /* bird: emx */
291#endif /* bird: emx */
292int putchar(int);
293int puts(const char *);
294int remove(const char *);
295int rename(const char *, const char *);
296void rewind(FILE *);
297int scanf(const char * __restrict, ...);
298void setbuf(FILE * __restrict, char * __restrict);
299int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
300int sprintf(char * __restrict, const char * __restrict, ...);
301int sscanf(const char * __restrict, const char * __restrict, ...);
302FILE *tmpfile(void);
303char *tmpnam(char *);
304int ungetc(int, FILE *);
305int vfprintf(FILE * __restrict, const char * __restrict,
306 __va_list);
307int vprintf(const char * __restrict, __va_list);
308int vsprintf(char * __restrict, const char * __restrict,
309 __va_list);
310
311#if __ISO_C_VISIBLE >= 1999
312int snprintf(char * __restrict, size_t, const char * __restrict,
313 ...) __printflike(3, 4);
314int vfscanf(FILE * __restrict, const char * __restrict, __va_list)
315 __scanflike(2, 0);
316int vscanf(const char * __restrict, __va_list) __scanflike(1, 0);
317int vsnprintf(char * __restrict, size_t, const char * __restrict,
318 __va_list) __printflike(3, 0);
319int vsscanf(const char * __restrict, const char * __restrict, __va_list)
320 __scanflike(2, 0);
321#endif
322
323/*
324 * Functions defined in all versions of POSIX 1003.1.
325 */
326#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506
327/* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */
328#define L_cuserid 9 /* bird: emx, was 17 */ /* legacy */
329#endif
330
331#if __POSIX_VISIBLE
332#define L_ctermid 260 /* bird: emx, was 1024 */ /* size for ctermid(3); PATH_MAX */
333
334/** @todo char *ctermid(char *); */
335FILE *fdopen(int, const char *);
336int fileno(FILE *);
337#endif /* __POSIX_VISIBLE */
338
339#if __POSIX_VISIBLE >= 199209
340int pclose(FILE *);
341FILE *popen(const char *, const char *);
342#endif
343
344#if __POSIX_VISIBLE >= 199506
345/** @todo int ftrylockfile(FILE *); */
346/** @todo void flockfile(FILE *); */
347/** @todo void funlockfile(FILE *); */
348
349/*
350 * These are normally used through macros as defined below, but POSIX
351 * requires functions as well.
352 */
353/** @todo int getc_unlocked(FILE *); */
354/** @todo int getchar_unlocked(void); */
355/** @todo int putc_unlocked(int, FILE *); */
356/** @todo int putchar_unlocked(int); */
357#endif
358#if __BSD_VISIBLE
359/** @todo void clearerr_unlocked(FILE *); */
360/** @todo int feof_unlocked(FILE *); */
361/** @todo int ferror_unlocked(FILE *); */
362/** @todo int fileno_unlocked(FILE *); */
363#endif
364
365#if __POSIX_VISIBLE >= 200112
366int fseeko(FILE *, __off_t, int);
367__off_t ftello(FILE *);
368#endif
369
370#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600
371int getw(FILE *);
372int putw(int, FILE *);
373#endif /* BSD or X/Open before issue 6 */
374
375#if __XSI_VISIBLE
376char *tempnam(const char *, const char *);
377#endif
378
379/*
380 * Routines that are purely local.
381 */
382#if __BSD_VISIBLE
383/** @todo int asprintf(char **, const char *, ...) __printflike(2, 3); */
384/** @todo char *ctermid_r(char *); */
385/** @todo char *fgetln(FILE *, size_t *); */
386#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3
387#define __ATTR_FORMAT_ARG __attribute__((__format_arg__(2)))
388#else
389#define __ATTR_FORMAT_ARG
390#endif
391/** @todo __const char *fmtcheck(const char *, const char *) __ATTR_FORMAT_ARG; */
392/** @todo int fpurge(FILE *); */
393void setbuffer(FILE *, char *, int);
394/** @todo int setlinebuf(FILE *); */
395/** @todo int vasprintf(char **, const char *, __va_list)
396 __printflike(2, 0); */
397
398/*
399 * The system error table contains messages for the first sys_nerr
400 * positive errno values. Use strerror() or strerror_r() from <string.h>
401 * instead.
402 */
403extern __const int sys_nerr;
404extern __const char *__const sys_errlist[];
405
406/*
407 * Stdio function-access interface.
408 */
409/** @todo FILE *funopen(const void *,
410 int (*)(void *, char *, int),
411 int (*)(void *, const char *, int),
412 fpos_t (*)(void *, fpos_t, int),
413 int (*)(void *)); */
414/** @todo #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) */
415/** @todo #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) */
416
417/*
418 * Portability hacks. See <sys/types.h>.
419 */
420#ifndef _FTRUNCATE_DECLARED
421#define _FTRUNCATE_DECLARED
422int ftruncate(int, __off_t);
423#endif
424#ifndef _LSEEK_DECLARED
425#define _LSEEK_DECLARED
426__off_t lseek(int, __off_t, int);
427#endif
428#ifndef _MMAP_DECLARED
429#define _MMAP_DECLARED
430void *mmap(void *, size_t, int, int, int, __off_t);
431#endif
432#ifndef _TRUNCATE_DECLARED
433#define _TRUNCATE_DECLARED
434int truncate(const char *, __off_t);
435#endif
436#endif /* __BSD_VISIBLE */
437
438#if 0 /* bird: Skip FreeBSD sepcific LIBC stuff. */
439/*
440 * Functions internal to the implementation.
441 */
442int __srget(FILE *);
443int __swbuf(int, FILE *);
444
445/*
446 * The __sfoo macros are here so that we can
447 * define function versions in the C library.
448 */
449#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
450#if defined(__GNUC__) && defined(__STDC__)
451static __inline int __sputc(int _c, FILE *_p) {
452 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
453 return (*_p->_p++ = _c);
454 else
455 return (__swbuf(_c, _p));
456}
457#else
458/*
459 * This has been tuned to generate reasonable code on the vax using pcc.
460 */
461#define __sputc(c, p) \
462 (--(p)->_w < 0 ? \
463 (p)->_w >= (p)->_lbfsize ? \
464 (*(p)->_p = (c)), *(p)->_p != '\n' ? \
465 (int)*(p)->_p++ : \
466 __swbuf('\n', p) : \
467 __swbuf((int)(c), p) : \
468 (*(p)->_p = (c), (int)*(p)->_p++))
469#endif
470
471#define __sfeof(p) (((p)->_flags & __SEOF) != 0)
472#define __sferror(p) (((p)->_flags & __SERR) != 0)
473#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
474#define __sfileno(p) ((p)->_file)
475
476#if __BSD_VISIBLE
477/*
478 * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12
479 * B.8.2.7 for the rationale behind the *_unlocked() macros.
480 */
481#define feof_unlocked(p) __sfeof(p)
482#define ferror_unlocked(p) __sferror(p)
483#define clearerr_unlocked(p) __sclearerr(p)
484#define fileno_unlocked(p) __sfileno(p)
485#endif
486#if __POSIX_VISIBLE >= 199506
487#define getc_unlocked(fp) __sgetc(fp)
488#define putc_unlocked(x, fp) __sputc(x, fp)
489
490#define getchar_unlocked() getc_unlocked(stdin)
491#define putchar_unlocked(x) putc_unlocked(x, stdout)
492#endif
493
494#endif /* bird: Skip FreeBSD sepcific LIBC stuff. */
495
496
497/* bird: start of EMX isms. */
498
499#if !defined (_IOREAD)
500/** @todo change to double underscore prefix to prevent confusion with
501 * setvbuf() constants. See the short rant about it above. */
502#define _IOREAD 0x01
503#define _IOWRT 0x02
504#define _IORW 0x04
505#define _IOEOF 0x08
506#define _IOERR 0x10
507#endif
508
509int _fill (FILE *);
510int _flush (int, FILE *);
511int _rmtmp (void);
512
513extern __inline__ int feof (FILE *_s)
514{
515 return (_s->_flags & _IOEOF ? 1 : 0);
516}
517
518extern __inline__ int ferror (FILE *_s)
519{
520 return (_s->_flags & _IOERR ? 1 : 0);
521}
522
523extern __inline__ int getchar (void) { return getc (stdin); }
524extern __inline__ int putchar (int _c) { return putc (_c, stdout); }
525
526#if !defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE)
527
528char *cuserid (char *);
529int fcloseall (void);
530int fgetchar (void);
531int flushall (void);
532int fputchar (int);
533
534#endif
535
536
537#if (!defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE)) \
538 || defined (_WITH_UNDERSCORE)
539
540int _fcloseall (void);
541FILE *_fassign (FILE *, FILE *);
542FILE *_fdopen (int, __const__ char *);
543int _fgetchar (void);
544int _flushall (void);
545int _fputchar (int);
546int _fseek_hdr (FILE *);
547int _fsetmode (FILE *, __const__ char *);
548FILE *_fsopen (__const__ char *, __const__ char *, int);
549int _getw (FILE *);
550char *_mfclose (FILE *);
551FILE *_mfopen (char *, __const__ char *, size_t, int);
552int _pclose (FILE *);
553FILE *_popen (__const__ char *, __const__ char *);
554int _putw (int, FILE *);
555void _setbuffer (FILE *, char *, int);
556int _snprintf (char *, size_t, __const__ char *, ...);
557char *_tempnam (__const__ char *, __const__ char *);
558int _vsnprintf (char *, size_t, __const__ char *, va_list);
559
560#endif
561/* bird: end of EMX isms. */
562
563__END_DECLS
564#endif /* !_STDIO_H_ */
565
Note: See TracBrowser for help on using the repository browser.