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

Last change on this file since 1570 was 1506, checked in by bird, 21 years ago

@unixroot. header reviews. ++

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