1:
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36:
37: #ifndef _STDIO_H_
38: #define _STDIO_H_
39:
40: #include <sys/cdefs.h>
41: #include <sys/featuretest.h>
42: #include <sys/ansi.h>
43:
44: #include <machine/ansi.h>
45:
46: #ifdef T2EX
47: #include <sys/types.h>
48: #endif
49:
50: #ifndef T2EX
51: #ifdef _BSD_SIZE_T_
52: typedef _BSD_SIZE_T_ size_t;
53: #undef _BSD_SIZE_T_
54: #endif
55: #else
56: #ifdef __size_t
57: typedef __size_t size_t;
58: #undef __size_t
59: #endif
60: #endif
61:
62: #include <sys/null.h>
63:
64: 65: 66: 67: 68:
69: #ifdef T2EX
70: #ifdef __off_t
71: typedef __off_t off_t;
72: #undef __off_t
73: #endif
74: #define __off_t off_t
75: #endif
76: #if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC)
77: typedef __off_t fpos_t;
78: #else
79: typedef struct __sfpos {
80: __off_t _pos;
81: } fpos_t;
82: #endif
83: #ifdef T2EX
84: #undef __off_t
85: #endif
86:
87: #define _FSTDIO
88:
89: 90: 91: 92: 93:
94:
95:
96: struct __sbuf {
97: unsigned char *_base;
98: int _size;
99: };
100:
101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126:
127: typedef struct __sFILE {
128: unsigned char *_p;
129: int _r;
130: int _w;
131: unsigned short _flags;
132: short _file;
133: struct __sbuf _bf;
134: int _lbfsize;
135:
136:
137: void *_cookie;
138: int (*_close)(void *);
139: int (*_read) (void *, char *, int);
140: fpos_t (*_seek) (void *, fpos_t, int);
141: int (*_write)(void *, const char *, int);
142:
143:
144: struct __sbuf _ext;
145:
146:
147: unsigned char *_up;
148: int _ur;
149:
150:
151: unsigned char _ubuf[3];
152: unsigned char _nbuf[1];
153:
154:
155: struct __sbuf _lb;
156:
157:
158: int _blksize;
159: fpos_t _offset;
160: } FILE;
161:
162: __BEGIN_DECLS
163: extern FILE __sF[];
164: __END_DECLS
165:
166: #define __SLBF 0x0001
167: #define __SNBF 0x0002
168: #define __SRD 0x0004
169: #define __SWR 0x0008
170:
171: #define __SRW 0x0010
172: #define __SEOF 0x0020
173: #define __SERR 0x0040
174: #define __SMBF 0x0080
175: #define __SAPP 0x0100
176: #define __SSTR 0x0200
177: #define __SOPT 0x0400
178: #define __SNPT 0x0800
179: #define __SOFF 0x1000
180: #define __SMOD 0x2000
181: #define __SALC 0x4000
182:
183: 184: 185: 186: 187: 188: 189: 190: 191:
192: #define _IOFBF 0
193: #define _IOLBF 1
194: #define _IONBF 2
195:
196: #define BUFSIZ 1024
197: #define EOF (-1)
198:
199: 200: 201: 202: 203:
204:
205: #define FOPEN_MAX 20
206: #define FILENAME_MAX 1024
207:
208:
209: #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
210: #define P_tmpdir "/var/tmp/"
211: #endif
212: #define L_tmpnam 1024
213:
214: #ifndef TMP_MAX
215: #define TMP_MAX 308915776
216: #endif
217:
218:
219: #ifndef SEEK_SET
220: #define SEEK_SET 0
221: #endif
222: #ifndef SEEK_CUR
223: #define SEEK_CUR 1
224: #endif
225: #ifndef SEEK_END
226: #define SEEK_END 2
227: #endif
228:
229: #define stdin (&__sF[0])
230: #define stdout (&__sF[1])
231: #define stderr (&__sF[2])
232:
233: 234: 235:
236: __BEGIN_DECLS
237: void clearerr(FILE *);
238: int fclose(FILE *);
239: int feof(FILE *);
240: int ferror(FILE *);
241: int fflush(FILE *);
242: int fgetc(FILE *);
243: int fgetpos(FILE * __restrict, fpos_t * __restrict);
244: char *fgets(char * __restrict, int, FILE * __restrict);
245: FILE *fopen(const char * __restrict , const char * __restrict);
246: int fprintf(FILE * __restrict , const char * __restrict, ...)
247: __attribute__((__format__(__printf__, 2, 3)));
248: int fputc(int, FILE *);
249: int fputs(const char * __restrict, FILE * __restrict);
250: size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
251: FILE *freopen(const char * __restrict, const char * __restrict,
252: FILE * __restrict);
253: int fscanf(FILE * __restrict, const char * __restrict, ...)
254: __attribute__((__format__(__scanf__, 2, 3)));
255: int fseek(FILE *, long, int);
256: int fsetpos(FILE *, const fpos_t *);
257: long ftell(FILE *);
258: size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
259: int getc(FILE *);
260: int getchar(void);
261: void perror(const char *);
262: int printf(const char * __restrict, ...)
263: __attribute__((__format__(__printf__, 1, 2)));
264: int putc(int, FILE *);
265: int putchar(int);
266: int puts(const char *);
267: int remove(const char *);
268: void rewind(FILE *);
269: int scanf(const char * __restrict, ...)
270: __attribute__((__format__(__scanf__, 1, 2)));
271: void setbuf(FILE * __restrict, char * __restrict);
272: int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
273: int sscanf(const char * __restrict, const char * __restrict, ...)
274: __attribute__((__format__(__scanf__, 2, 3)));
275: FILE *tmpfile(void);
276: int ungetc(int, FILE *);
277: int vfprintf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_)
278: __attribute__((__format__(__printf__, 2, 0)));
279: int vprintf(const char * __restrict, _BSD_VA_LIST_)
280: __attribute__((__format__(__printf__, 1, 0)));
281:
282: #ifndef __AUDIT__
283: char *gets(char *);
284: int sprintf(char * __restrict, const char * __restrict, ...)
285: __attribute__((__format__(__printf__, 2, 3)));
286: char *tmpnam(char *);
287: int vsprintf(char * __restrict, const char * __restrict,
288: _BSD_VA_LIST_)
289: __attribute__((__format__(__printf__, 2, 0)));
290: #endif
291:
292: #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
293: int rename (const char *, const char *) __RENAME(__posix_rename);
294: #else
295: int rename (const char *, const char *);
296: #endif
297: __END_DECLS
298:
299: 300: 301:
302: #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
303: defined(_NETBSD_SOURCE)
304: #define L_ctermid 1024
305: #define L_cuserid 9
306:
307: __BEGIN_DECLS
308: char *ctermid(char *);
309: #ifndef __CUSERID_DECLARED
310: #define __CUSERID_DECLARED
311:
312: char *cuserid(char *);
313: #endif
314: FILE *fdopen(int, const char *);
315: int fileno(FILE *);
316: __END_DECLS
317: #endif
318:
319: 320: 321:
322: #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
323: defined(_REENTRANT) || defined(_NETBSD_SOURCE)
324: __BEGIN_DECLS
325: void flockfile(FILE *);
326: int ftrylockfile(FILE *);
327: void funlockfile(FILE *);
328: int getc_unlocked(FILE *);
329: int getchar_unlocked(void);
330: int putc_unlocked(int, FILE *);
331: int putchar_unlocked(int);
332: __END_DECLS
333: #endif
334:
335: 336: 337:
338: #if (_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 2 || \
339: defined(_NETBSD_SOURCE)
340: __BEGIN_DECLS
341: int pclose(FILE *);
342: FILE *popen(const char *, const char *);
343: __END_DECLS
344: #endif
345:
346: 347: 348:
349: #if ((__STDC_VERSION__ - 0) >= 199901L) || \
350: ((_POSIX_C_SOURCE - 0) >= 200112L) || \
351: (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
352: ((_XOPEN_SOURCE - 0) >= 500) || \
353: defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
354: __BEGIN_DECLS
355: int snprintf(char * __restrict, size_t, const char * __restrict, ...)
356: __attribute__((__format__(__printf__, 3, 4)));
357: int vsnprintf(char * __restrict, size_t, const char * __restrict,
358: _BSD_VA_LIST_)
359: __attribute__((__format__(__printf__, 3, 0)));
360: __END_DECLS
361: #endif
362:
363: 364: 365:
366: #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
367: __BEGIN_DECLS
368: int getw(FILE *);
369: int putw(int, FILE *);
370:
371: #ifndef __AUDIT__
372: char *tempnam(const char *, const char *);
373: #endif
374: __END_DECLS
375: #endif
376:
377: 378: 379:
380: #if (_XOPEN_SOURCE - 0) >= 500 || defined(_LARGEFILE_SOURCE) || \
381: defined(_NETBSD_SOURCE)
382:
383: #ifndef T2EX
384: #ifndef off_t
385: typedef __off_t off_t;
386: #define off_t __off_t
387: #endif
388: #else
389: #ifdef __off_t
390: typedef __off_t off_t;
391: #undef __off_t
392: #endif
393: #endif
394:
395: __BEGIN_DECLS
396: int fseeko(FILE *, off_t, int);
397: off_t ftello(FILE *);
398: __END_DECLS
399: #endif
400:
401: 402: 403: 404:
405: #if defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
406: __BEGIN_DECLS
407: int vscanf(const char * __restrict, _BSD_VA_LIST_)
408: __attribute__((__format__(__scanf__, 1, 0)));
409: int vfscanf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_)
410: __attribute__((__format__(__scanf__, 2, 0)));
411: int vsscanf(const char * __restrict, const char * __restrict,
412: _BSD_VA_LIST_)
413: __attribute__((__format__(__scanf__, 2, 0)));
414: __END_DECLS
415: #endif
416:
417: 418: 419:
420: #if defined(_NETBSD_SOURCE)
421:
422: #define FPARSELN_UNESCESC 0x01
423: #define FPARSELN_UNESCCONT 0x02
424: #define FPARSELN_UNESCCOMM 0x04
425: #define FPARSELN_UNESCREST 0x08
426: #define FPARSELN_UNESCALL 0x0f
427:
428: __BEGIN_DECLS
429: int asprintf(char ** __restrict, const char * __restrict, ...)
430: __attribute__((__format__(__printf__, 2, 3)));
431: char *fgetln(FILE * __restrict, size_t * __restrict);
432: char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
433: int fpurge(FILE *);
434: void setbuffer(FILE *, char *, int);
435: int setlinebuf(FILE *);
436: int vasprintf(char ** __restrict, const char * __restrict,
437: _BSD_VA_LIST_)
438: __attribute__((__format__(__printf__, 2, 0)));
439: const char *fmtcheck(const char *, const char *)
440: __attribute__((__format_arg__(2)));
441: __END_DECLS
442:
443: 444: 445:
446: __BEGIN_DECLS
447: FILE *funopen(const void *,
448: int (*)(void *, char *, int),
449: int (*)(void *, const char *, int),
450: fpos_t (*)(void *, fpos_t, int),
451: int (*)(void *));
452: __END_DECLS
453: #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
454: #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
455: #endif
456:
457: 458: 459:
460: __BEGIN_DECLS
461: int __srget(FILE *);
462: int __swbuf(int, FILE *);
463: __END_DECLS
464:
465: 466: 467: 468:
469: #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
470: #if defined(__GNUC__) && defined(__STDC__)
471: static __inline int __sputc(int _c, FILE *_p) {
472: if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
473: return (*_p->_p++ = _c);
474: else
475: return (__swbuf(_c, _p));
476: }
477: #else
478: 479: 480:
481: #define __sputc(c, p) \
482: (--(p)->_w < 0 ? \
483: (p)->_w >= (p)->_lbfsize ? \
484: (*(p)->_p = (c)), *(p)->_p != '\n' ? \
485: (int)*(p)->_p++ : \
486: __swbuf('\n', p) : \
487: __swbuf((int)(c), p) : \
488: (*(p)->_p = (c), (int)*(p)->_p++))
489: #endif
490:
491: #define __sfeof(p) (((p)->_flags & __SEOF) != 0)
492: #define __sferror(p) (((p)->_flags & __SERR) != 0)
493: #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
494: #define __sfileno(p) \
495: ((p)->_file == -1 ? -1 : (int)(unsigned short)(p)->_file)
496:
497: #ifndef __lint__
498: #if !defined(_REENTRANT) && !defined(_PTHREADS)
499: #define feof(p) __sfeof(p)
500: #define ferror(p) __sferror(p)
501: #define clearerr(p) __sclearerr(p)
502:
503: #define getc(fp) __sgetc(fp)
504: #define putc(x, fp) __sputc(x, fp)
505: #endif
506: #endif
507:
508: #define getchar() getc(stdin)
509: #define putchar(x) putc(x, stdout)
510:
511: #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
512: defined(_NETBSD_SOURCE)
513: #if !defined(_REENTRANT) && !defined(_PTHREADS)
514: #define fileno(p) __sfileno(p)
515: #endif
516: #endif
517:
518: #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
519: defined(_REENTRANT) || defined(_NETBSD_SOURCE)
520: #define getc_unlocked(fp) __sgetc(fp)
521: #define putc_unlocked(x, fp) __sputc(x, fp)
522:
523: #define getchar_unlocked() getc_unlocked(stdin)
524: #define putchar_unlocked(x) putc_unlocked(x, stdout)
525: #endif
526:
527: #if _FORTIFY_SOURCE > 0
528: #include <ssp/stdio.h>
529: #endif
530:
531: #endif