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

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

#668: Initial changed related to Large File Support (>2GB).

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