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

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

Fixed a couple of errors in the migration.

  • Property cvs2svn:cvs-rev set to 1.7
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 18.0 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 _streamv[];
200__END_DECLS
201
202#define __stdinp (&_streamv[0])
203#define __stdoutp (&_streamv[1])
204#define __stderrp (&_streamv[2])
205
206#endif /* bird: EMX specific FILE stuff ends. */
207
208
209/*
210 * The following three definitions are for ANSI C, which took them
211 * from System V, which brilliantly took internal interface macros and
212 * made them official arguments to setvbuf(), without renaming them.
213 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
214 *
215 * Although numbered as their counterparts above, the implementation
216 * does not rely on this.
217 */
218#define _IOFBF 0 /* setvbuf should set fully buffered */
219#define _IOLBF 0x20 /* bird: emx, was 1 */ /* setvbuf should set line buffered */
220#define _IONBF 0x40 /* bird: emx, was 2 */ /* setvbuf should set unbuffered */
221
222#define BUFSIZ 5120 /* bird: emx, was 1024 */ /* size of buffer used by setbuf */
223#define EOF (-1)
224
225/*
226 * FOPEN_MAX is a minimum maximum, and is the number of streams that
227 * stdio can provide without attempting to allocate further resources
228 * (which could fail). Do not use this for anything.
229 */
230 /* must be == _POSIX_STREAM_MAX <limits.h> */
231#define FOPEN_MAX 14 /* bird: emx, was 20 */ /* must be <= OPEN_MAX <sys/syslimits.h> */
232#define FILENAME_MAX 260 /* bird: emx, was 1024 */ /* must be <= PATH_MAX <sys/syslimits.h> */
233
234/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
235#if __XSI_VISIBLE
236#define P_tmpdir "." /* bird: emx, was "/var/tmp/" */
237#endif
238#define L_tmpnam 260 /* bird: emx, was 1024 */ /* XXX must be == PATH_MAX */
239#define TMP_MAX 1000 /* bird: emx, was 308915776 */
240
241#ifndef SEEK_SET
242#define SEEK_SET 0 /* set file offset to offset */
243#endif
244#ifndef SEEK_CUR
245#define SEEK_CUR 1 /* set file offset to current plus offset */
246#endif
247#ifndef SEEK_END
248#define SEEK_END 2 /* set file offset to EOF plus offset */
249#endif
250
251#define stdin __stdinp
252#define stdout __stdoutp
253#define stderr __stderrp
254
255__BEGIN_DECLS
256/*
257 * Functions defined in ANSI C standard.
258 */
259void clearerr(FILE *);
260int fclose(FILE *);
261int feof(FILE *);
262int ferror(FILE *);
263int fflush(FILE *);
264int fgetc(FILE *);
265int fgetpos(FILE * __restrict, fpos_t * __restrict);
266char *fgets(char * __restrict, int, FILE * __restrict);
267FILE *fopen(const char * __restrict, const char * __restrict);
268int fprintf(FILE * __restrict, const char * __restrict, ...);
269int fputc(int, FILE *);
270int fputs(const char * __restrict, FILE * __restrict);
271size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
272FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict);
273int fscanf(FILE * __restrict, const char * __restrict, ...);
274int fseek(FILE *, long, int);
275int fsetpos(FILE *, const fpos_t *);
276long ftell(FILE *);
277size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
278#if 0 /* bird: emx */
279int getc(FILE *);
280#else /* bird: emx */
281/** @todo: Check the standard, if this is correct or not. declaration might be required. */
282#define getc(s) fgetc(s) /* bird: emx */
283#endif /* bird: emx */
284int getchar(void);
285char *gets(char *);
286void perror(const char *);
287int printf(const char * __restrict, ...);
288#if 0 /* bird: emx */
289int putc(int, FILE *);
290#else /* bird: emx */
291/** @todo: Check the standard, if this is correct or not. declaration might be required. */
292#define putc(c,s) fputc(c,s) /* bird: emx */
293#endif /* bird: emx */
294int putchar(int);
295int puts(const char *);
296int remove(const char *);
297int rename(const char *, const char *);
298void rewind(FILE *);
299int scanf(const char * __restrict, ...);
300void setbuf(FILE * __restrict, char * __restrict);
301int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
302int sprintf(char * __restrict, const char * __restrict, ...);
303int sscanf(const char * __restrict, const char * __restrict, ...);
304FILE *tmpfile(void);
305char *tmpnam(char *);
306int ungetc(int, FILE *);
307int vfprintf(FILE * __restrict, const char * __restrict,
308 __va_list);
309int vprintf(const char * __restrict, __va_list);
310int vsprintf(char * __restrict, const char * __restrict,
311 __va_list);
312
313#if __ISO_C_VISIBLE >= 1999
314int snprintf(char * __restrict, size_t, const char * __restrict,
315 ...) __printflike(3, 4);
316int vfscanf(FILE * __restrict, const char * __restrict, __va_list)
317 __scanflike(2, 0);
318int vscanf(const char * __restrict, __va_list) __scanflike(1, 0);
319int vsnprintf(char * __restrict, size_t, const char * __restrict,
320 __va_list) __printflike(3, 0);
321int vsscanf(const char * __restrict, const char * __restrict, __va_list)
322 __scanflike(2, 0);
323#endif
324
325/*
326 * Functions defined in all versions of POSIX 1003.1.
327 */
328#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506
329/* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */
330#define L_cuserid 9 /* bird: emx, was 17 */ /* legacy */
331#endif
332
333#if __POSIX_VISIBLE
334#define L_ctermid 260 /* bird: emx, was 1024 */ /* size for ctermid(3); PATH_MAX */
335
336/** @todo char *ctermid(char *); */
337FILE *fdopen(int, const char *);
338int fileno(FILE *);
339#endif /* __POSIX_VISIBLE */
340
341#if __POSIX_VISIBLE >= 199209
342int pclose(FILE *);
343FILE *popen(const char *, const char *);
344#endif
345
346#if __POSIX_VISIBLE >= 199506
347/** @todo int ftrylockfile(FILE *); */
348/** @todo void flockfile(FILE *); */
349/** @todo void funlockfile(FILE *); */
350
351/*
352 * These are normally used through macros as defined below, but POSIX
353 * requires functions as well.
354 */
355/** @todo int getc_unlocked(FILE *); */
356/** @todo int getchar_unlocked(void); */
357/** @todo int putc_unlocked(int, FILE *); */
358/** @todo int putchar_unlocked(int); */
359#endif
360#if __BSD_VISIBLE
361/** @todo void clearerr_unlocked(FILE *); */
362/** @todo int feof_unlocked(FILE *); */
363/** @todo int ferror_unlocked(FILE *); */
364/** @todo int fileno_unlocked(FILE *); */
365#endif
366
367#if __POSIX_VISIBLE >= 200112
368int fseeko(FILE *, __off_t, int);
369__off_t ftello(FILE *);
370#endif
371
372#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600
373int getw(FILE *);
374int putw(int, FILE *);
375#endif /* BSD or X/Open before issue 6 */
376
377#if __XSI_VISIBLE
378char *tempnam(const char *, const char *);
379#endif
380
381/*
382 * Routines that are purely local.
383 */
384#if __BSD_VISIBLE
385/** @todo int asprintf(char **, const char *, ...) __printflike(2, 3); */
386/** @todo char *ctermid_r(char *); */
387/** @todo char *fgetln(FILE *, size_t *); */
388#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3
389#define __ATTR_FORMAT_ARG __attribute__((__format_arg__(2)))
390#else
391#define __ATTR_FORMAT_ARG
392#endif
393/** @todo __const char *fmtcheck(const char *, const char *) __ATTR_FORMAT_ARG; */
394/** @todo int fpurge(FILE *); */
395void setbuffer(FILE *, char *, int);
396/** @todo int setlinebuf(FILE *); */
397/** @todo int vasprintf(char **, const char *, __va_list)
398 __printflike(2, 0); */
399
400/*
401 * The system error table contains messages for the first sys_nerr
402 * positive errno values. Use strerror() or strerror_r() from <string.h>
403 * instead.
404 */
405extern __const int sys_nerr;
406extern __const char *__const sys_errlist[];
407
408/*
409 * Stdio function-access interface.
410 */
411/** @todo FILE *funopen(const void *,
412 int (*)(void *, char *, int),
413 int (*)(void *, const char *, int),
414 fpos_t (*)(void *, fpos_t, int),
415 int (*)(void *)); */
416/** @todo #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) */
417/** @todo #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) */
418
419/*
420 * Portability hacks. See <sys/types.h>.
421 */
422#ifndef _FTRUNCATE_DECLARED
423#define _FTRUNCATE_DECLARED
424int ftruncate(int, __off_t);
425#endif
426#ifndef _LSEEK_DECLARED
427#define _LSEEK_DECLARED
428__off_t lseek(int, __off_t, int);
429#endif
430#ifndef _MMAP_DECLARED
431#define _MMAP_DECLARED
432void *mmap(void *, size_t, int, int, int, __off_t);
433#endif
434#ifndef _TRUNCATE_DECLARED
435#define _TRUNCATE_DECLARED
436int truncate(const char *, __off_t);
437#endif
438#endif /* __BSD_VISIBLE */
439
440#if 0 /* bird: Skip FreeBSD sepcific LIBC stuff. */
441/*
442 * Functions internal to the implementation.
443 */
444int __srget(FILE *);
445int __swbuf(int, FILE *);
446
447/*
448 * The __sfoo macros are here so that we can
449 * define function versions in the C library.
450 */
451#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
452#if defined(__GNUC__) && defined(__STDC__)
453static __inline int __sputc(int _c, FILE *_p) {
454 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
455 return (*_p->_p++ = _c);
456 else
457 return (__swbuf(_c, _p));
458}
459#else
460/*
461 * This has been tuned to generate reasonable code on the vax using pcc.
462 */
463#define __sputc(c, p) \
464 (--(p)->_w < 0 ? \
465 (p)->_w >= (p)->_lbfsize ? \
466 (*(p)->_p = (c)), *(p)->_p != '\n' ? \
467 (int)*(p)->_p++ : \
468 __swbuf('\n', p) : \
469 __swbuf((int)(c), p) : \
470 (*(p)->_p = (c), (int)*(p)->_p++))
471#endif
472
473#define __sfeof(p) (((p)->_flags & __SEOF) != 0)
474#define __sferror(p) (((p)->_flags & __SERR) != 0)
475#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
476#define __sfileno(p) ((p)->_file)
477
478#if __BSD_VISIBLE
479/*
480 * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12
481 * B.8.2.7 for the rationale behind the *_unlocked() macros.
482 */
483#define feof_unlocked(p) __sfeof(p)
484#define ferror_unlocked(p) __sferror(p)
485#define clearerr_unlocked(p) __sclearerr(p)
486#define fileno_unlocked(p) __sfileno(p)
487#endif
488#if __POSIX_VISIBLE >= 199506
489#define getc_unlocked(fp) __sgetc(fp)
490#define putc_unlocked(x, fp) __sputc(x, fp)
491
492#define getchar_unlocked() getc_unlocked(stdin)
493#define putchar_unlocked(x) putc_unlocked(x, stdout)
494#endif
495
496#endif /* bird: Skip FreeBSD sepcific LIBC stuff. */
497
498
499/* bird: start of EMX isms. */
500
501#if !defined (_IOREAD)
502/** @todo change to double underscore prefix to prevent confusion with
503 * setvbuf() constants. See the short rant about it above. */
504#define _IOREAD 0x01
505#define _IOWRT 0x02
506#define _IORW 0x04
507#define _IOEOF 0x08
508#define _IOERR 0x10
509#endif
510
511int _fill (FILE *);
512int _flush (int, FILE *);
513int _rmtmp (void);
514
515extern __inline__ int feof (FILE *_s)
516{
517 return (_s->_flags & _IOEOF ? 1 : 0);
518}
519
520extern __inline__ int ferror (FILE *_s)
521{
522 return (_s->_flags & _IOERR ? 1 : 0);
523}
524
525extern __inline__ int getchar (void) { return getc (stdin); }
526extern __inline__ int putchar (int _c) { return putc (_c, stdout); }
527
528#if !defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE)
529
530char *cuserid (char *);
531int fcloseall (void);
532int fgetchar (void);
533int flushall (void);
534int fputchar (int);
535
536#endif
537
538
539#if (!defined (__STRICT_ANSI__) && !defined (_POSIX_SOURCE)) \
540 || defined (_WITH_UNDERSCORE)
541
542int _fcloseall (void);
543FILE *_fassign (FILE *, FILE *);
544FILE *_fdopen (int, __const__ char *);
545int _fgetchar (void);
546int _flushall (void);
547int _fputchar (int);
548int _fseek_hdr (FILE *);
549int _fsetmode (FILE *, __const__ char *);
550FILE *_fsopen (__const__ char *, __const__ char *, int);
551int _getw (FILE *);
552char *_mfclose (FILE *);
553FILE *_mfopen (char *, __const__ char *, size_t, int);
554int _pclose (FILE *);
555FILE *_popen (__const__ char *, __const__ char *);
556int _putw (int, FILE *);
557void _setbuffer (FILE *, char *, int);
558int _snprintf (char *, size_t, __const__ char *, ...);
559char *_tempnam (__const__ char *, __const__ char *);
560int _vsnprintf (char *, size_t, __const__ char *, va_list);
561
562#endif
563/* bird: end of EMX isms. */
564
565__END_DECLS
566#endif /* !_STDIO_H_ */
567
Note: See TracBrowser for help on using the repository browser.