1*0a6a1f1dSLionel Sambuc /* $NetBSD: stdio.h,v 1.96 2015/03/24 07:44:52 wiz Exp $ */
22fe8fb19SBen Gras
32fe8fb19SBen Gras /*-
42fe8fb19SBen Gras * Copyright (c) 1990, 1993
52fe8fb19SBen Gras * The Regents of the University of California. All rights reserved.
69865aeaaSBen Gras *
72fe8fb19SBen Gras * This code is derived from software contributed to Berkeley by
82fe8fb19SBen Gras * Chris Torek.
92fe8fb19SBen Gras *
102fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without
112fe8fb19SBen Gras * modification, are permitted provided that the following conditions
122fe8fb19SBen Gras * are met:
132fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright
142fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer.
152fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
162fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the
172fe8fb19SBen Gras * documentation and/or other materials provided with the distribution.
182fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors
192fe8fb19SBen Gras * may be used to endorse or promote products derived from this software
202fe8fb19SBen Gras * without specific prior written permission.
212fe8fb19SBen Gras *
222fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
232fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
242fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
252fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
262fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
272fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
282fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
292fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
302fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
312fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
322fe8fb19SBen Gras * SUCH DAMAGE.
332fe8fb19SBen Gras *
342fe8fb19SBen Gras * @(#)stdio.h 8.5 (Berkeley) 4/29/95
359865aeaaSBen Gras */
369865aeaaSBen Gras
372fe8fb19SBen Gras #ifndef _STDIO_H_
382fe8fb19SBen Gras #define _STDIO_H_
399865aeaaSBen Gras
402fe8fb19SBen Gras #include <sys/cdefs.h>
412fe8fb19SBen Gras #include <sys/featuretest.h>
422fe8fb19SBen Gras #include <sys/ansi.h>
432fe8fb19SBen Gras
442fe8fb19SBen Gras #ifdef _BSD_SIZE_T_
452fe8fb19SBen Gras typedef _BSD_SIZE_T_ size_t;
462fe8fb19SBen Gras #undef _BSD_SIZE_T_
479865aeaaSBen Gras #endif
482fe8fb19SBen Gras #ifdef _BSD_SSIZE_T_
492fe8fb19SBen Gras typedef _BSD_SSIZE_T_ ssize_t;
502fe8fb19SBen Gras #undef _BSD_SSIZE_T_
512fe8fb19SBen Gras #endif
529865aeaaSBen Gras
53f14fb602SLionel Sambuc #if defined(_POSIX_C_SOURCE)
54f14fb602SLionel Sambuc #ifndef __VA_LIST_DECLARED
55f14fb602SLionel Sambuc typedef __va_list va_list;
56f14fb602SLionel Sambuc #define __VA_LIST_DECLARED
57f14fb602SLionel Sambuc #endif
58f14fb602SLionel Sambuc #endif
59f14fb602SLionel Sambuc
602fe8fb19SBen Gras #include <sys/null.h>
61dbde088dSArun Thomas
629865aeaaSBen Gras /*
632fe8fb19SBen Gras * This is fairly grotesque, but pure ANSI code must not inspect the
642fe8fb19SBen Gras * innards of an fpos_t anyway. The library internally uses off_t,
652fe8fb19SBen Gras * which we assume is exactly as big as eight chars.
669865aeaaSBen Gras */
672fe8fb19SBen Gras typedef struct __sfpos {
682fe8fb19SBen Gras __off_t _pos;
69f14fb602SLionel Sambuc __mbstate_t _mbstate_in, _mbstate_out;
702fe8fb19SBen Gras } fpos_t;
712fe8fb19SBen Gras
722fe8fb19SBen Gras #define _FSTDIO /* Define for new stdio with functions. */
732fe8fb19SBen Gras
742fe8fb19SBen Gras /*
752fe8fb19SBen Gras * NB: to fit things in six character monocase externals, the stdio
762fe8fb19SBen Gras * code uses the prefix `__s' for stdio objects, typically followed
772fe8fb19SBen Gras * by a three-character attempt at a mnemonic.
782fe8fb19SBen Gras */
792fe8fb19SBen Gras
802fe8fb19SBen Gras /* stdio buffers */
812fe8fb19SBen Gras struct __sbuf {
822fe8fb19SBen Gras unsigned char *_base;
832fe8fb19SBen Gras int _size;
842fe8fb19SBen Gras };
852fe8fb19SBen Gras
862fe8fb19SBen Gras /*
872fe8fb19SBen Gras * stdio state variables.
882fe8fb19SBen Gras *
892fe8fb19SBen Gras * The following always hold:
902fe8fb19SBen Gras *
912fe8fb19SBen Gras * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
922fe8fb19SBen Gras * _lbfsize is -_bf._size, else _lbfsize is 0
932fe8fb19SBen Gras * if _flags&__SRD, _w is 0
942fe8fb19SBen Gras * if _flags&__SWR, _r is 0
952fe8fb19SBen Gras *
962fe8fb19SBen Gras * This ensures that the getc and putc macros (or inline functions) never
972fe8fb19SBen Gras * try to write or read from a file that is in `read' or `write' mode.
982fe8fb19SBen Gras * (Moreover, they can, and do, automatically switch from read mode to
992fe8fb19SBen Gras * write mode, and back, on "r+" and "w+" files.)
1002fe8fb19SBen Gras *
1012fe8fb19SBen Gras * _lbfsize is used only to make the inline line-buffered output stream
1022fe8fb19SBen Gras * code as compact as possible.
1032fe8fb19SBen Gras *
1042fe8fb19SBen Gras * _ub, _up, and _ur are used when ungetc() pushes back more characters
1052fe8fb19SBen Gras * than fit in the current _bf, or when ungetc() pushes back a character
1062fe8fb19SBen Gras * that does not match the previous one in _bf. When this happens,
1072fe8fb19SBen Gras * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
1082fe8fb19SBen Gras * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
1092fe8fb19SBen Gras *
1102fe8fb19SBen Gras * NB: see WARNING above before changing the layout of this structure!
1112fe8fb19SBen Gras */
1122fe8fb19SBen Gras typedef struct __sFILE {
1132fe8fb19SBen Gras unsigned char *_p; /* current position in (some) buffer */
1142fe8fb19SBen Gras int _r; /* read space left for getc() */
1152fe8fb19SBen Gras int _w; /* write space left for putc() */
1162fe8fb19SBen Gras unsigned short _flags; /* flags, below; this FILE is free if 0 */
1172fe8fb19SBen Gras short _file; /* fileno, if Unix descriptor, else -1 */
1182fe8fb19SBen Gras struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
1192fe8fb19SBen Gras int _lbfsize; /* 0 or -_bf._size, for inline putc */
1202fe8fb19SBen Gras
1212fe8fb19SBen Gras /* operations */
1222fe8fb19SBen Gras void *_cookie; /* cookie passed to io functions */
1232fe8fb19SBen Gras int (*_close)(void *);
124f14fb602SLionel Sambuc ssize_t (*_read) (void *, void *, size_t);
125f14fb602SLionel Sambuc __off_t (*_seek) (void *, __off_t, int);
126f14fb602SLionel Sambuc ssize_t (*_write)(void *, const void *, size_t);
1272fe8fb19SBen Gras
1282fe8fb19SBen Gras /* file extension */
1292fe8fb19SBen Gras struct __sbuf _ext;
1302fe8fb19SBen Gras
1312fe8fb19SBen Gras /* separate buffer for long sequences of ungetc() */
1322fe8fb19SBen Gras unsigned char *_up; /* saved _p when _p is doing ungetc data */
1332fe8fb19SBen Gras int _ur; /* saved _r when _r is counting ungetc data */
1342fe8fb19SBen Gras
1352fe8fb19SBen Gras /* tricks to meet minimum requirements even when malloc() fails */
1362fe8fb19SBen Gras unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
1372fe8fb19SBen Gras unsigned char _nbuf[1]; /* guarantee a getc() buffer */
1382fe8fb19SBen Gras
139f14fb602SLionel Sambuc int (*_flush)(void *);
1402fe8fb19SBen Gras /* Formerly used by fgetln/fgetwln; kept for binary compatibility */
141f14fb602SLionel Sambuc char _lb_unused[sizeof(struct __sbuf) - sizeof(int (*)(void *))];
1422fe8fb19SBen Gras
1432fe8fb19SBen Gras /* Unix stdio files get aligned to block boundaries on fseek() */
1442fe8fb19SBen Gras int _blksize; /* stat.st_blksize (may be != _bf._size) */
145f14fb602SLionel Sambuc __off_t _offset; /* current lseek offset */
1469865aeaaSBen Gras } FILE;
1479865aeaaSBen Gras
1482fe8fb19SBen Gras __BEGIN_DECLS
149f14fb602SLionel Sambuc extern FILE __sF[3];
1502fe8fb19SBen Gras __END_DECLS
1519865aeaaSBen Gras
1522fe8fb19SBen Gras #define __SLBF 0x0001 /* line buffered */
1532fe8fb19SBen Gras #define __SNBF 0x0002 /* unbuffered */
1542fe8fb19SBen Gras #define __SRD 0x0004 /* OK to read */
1552fe8fb19SBen Gras #define __SWR 0x0008 /* OK to write */
1562fe8fb19SBen Gras /* RD and WR are never simultaneously asserted */
1572fe8fb19SBen Gras #define __SRW 0x0010 /* open for reading & writing */
1582fe8fb19SBen Gras #define __SEOF 0x0020 /* found EOF */
1592fe8fb19SBen Gras #define __SERR 0x0040 /* found error */
1602fe8fb19SBen Gras #define __SMBF 0x0080 /* _buf is from malloc */
1612fe8fb19SBen Gras #define __SAPP 0x0100 /* fdopen()ed in append mode */
1622fe8fb19SBen Gras #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
1632fe8fb19SBen Gras #define __SOPT 0x0400 /* do fseek() optimization */
1642fe8fb19SBen Gras #define __SNPT 0x0800 /* do not do fseek() optimization */
1652fe8fb19SBen Gras #define __SOFF 0x1000 /* set iff _offset is in fact correct */
1662fe8fb19SBen Gras #define __SMOD 0x2000 /* true => fgetln modified _p text */
1672fe8fb19SBen Gras #define __SALC 0x4000 /* allocate string space dynamically */
1682fe8fb19SBen Gras
1692fe8fb19SBen Gras /*
1702fe8fb19SBen Gras * The following three definitions are for ANSI C, which took them
1712fe8fb19SBen Gras * from System V, which brilliantly took internal interface macros and
1722fe8fb19SBen Gras * made them official arguments to setvbuf(), without renaming them.
1732fe8fb19SBen Gras * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
1742fe8fb19SBen Gras *
1752fe8fb19SBen Gras * Although numbered as their counterparts above, the implementation
1762fe8fb19SBen Gras * does not rely on this.
1779865aeaaSBen Gras */
1782fe8fb19SBen Gras #define _IOFBF 0 /* setvbuf should set fully buffered */
1792fe8fb19SBen Gras #define _IOLBF 1 /* setvbuf should set line buffered */
1802fe8fb19SBen Gras #define _IONBF 2 /* setvbuf should set unbuffered */
1819865aeaaSBen Gras
1822fe8fb19SBen Gras #define BUFSIZ 1024 /* size of buffer used by setbuf */
1839865aeaaSBen Gras #define EOF (-1)
1849865aeaaSBen Gras
1852fe8fb19SBen Gras /*
1862fe8fb19SBen Gras * FOPEN_MAX is a minimum maximum, and is the number of streams that
1872fe8fb19SBen Gras * stdio can provide without attempting to allocate further resources
1882fe8fb19SBen Gras * (which could fail). Do not use this for anything.
1892fe8fb19SBen Gras */
1902fe8fb19SBen Gras /* must be == _POSIX_STREAM_MAX <limits.h> */
1912fe8fb19SBen Gras #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
1929335f807SLionel Sambuc #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
1939865aeaaSBen Gras
1942fe8fb19SBen Gras /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
1952fe8fb19SBen Gras #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
1962fe8fb19SBen Gras #define P_tmpdir "/var/tmp/"
1972fe8fb19SBen Gras #endif
1982fe8fb19SBen Gras #define L_tmpnam 1024 /* XXX must be == PATH_MAX */
1992fe8fb19SBen Gras /* Always ensure that this is consistent with <limits.h> */
2002fe8fb19SBen Gras #ifndef TMP_MAX
2012fe8fb19SBen Gras #define TMP_MAX 308915776 /* Legacy */
2029865aeaaSBen Gras #endif
2039865aeaaSBen Gras
2042fe8fb19SBen Gras /* Always ensure that these are consistent with <fcntl.h> and <unistd.h>! */
2052fe8fb19SBen Gras #ifndef SEEK_SET
2062fe8fb19SBen Gras #define SEEK_SET 0 /* set file offset to offset */
2072fe8fb19SBen Gras #endif
2082fe8fb19SBen Gras #ifndef SEEK_CUR
2092fe8fb19SBen Gras #define SEEK_CUR 1 /* set file offset to current plus offset */
2102fe8fb19SBen Gras #endif
2112fe8fb19SBen Gras #ifndef SEEK_END
2122fe8fb19SBen Gras #define SEEK_END 2 /* set file offset to EOF plus offset */
2132fe8fb19SBen Gras #endif
2141cee6fe9SArun Thomas
2152fe8fb19SBen Gras #define stdin (&__sF[0])
2162fe8fb19SBen Gras #define stdout (&__sF[1])
2172fe8fb19SBen Gras #define stderr (&__sF[2])
2182fe8fb19SBen Gras
2192fe8fb19SBen Gras /*
2202fe8fb19SBen Gras * Functions defined in ANSI C standard.
2212fe8fb19SBen Gras */
2222fe8fb19SBen Gras __BEGIN_DECLS
2232fe8fb19SBen Gras void clearerr(FILE *);
2242fe8fb19SBen Gras int fclose(FILE *);
2252fe8fb19SBen Gras int feof(FILE *);
2262fe8fb19SBen Gras int ferror(FILE *);
2272fe8fb19SBen Gras int fflush(FILE *);
2282fe8fb19SBen Gras int fgetc(FILE *);
2292fe8fb19SBen Gras char *fgets(char * __restrict, int, FILE * __restrict);
2302fe8fb19SBen Gras FILE *fopen(const char * __restrict , const char * __restrict);
2312fe8fb19SBen Gras int fprintf(FILE * __restrict, const char * __restrict, ...)
2322fe8fb19SBen Gras __printflike(2, 3);
2332fe8fb19SBen Gras int fputc(int, FILE *);
2342fe8fb19SBen Gras int fputs(const char * __restrict, FILE * __restrict);
2352fe8fb19SBen Gras size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
2362fe8fb19SBen Gras FILE *freopen(const char * __restrict, const char * __restrict,
2372fe8fb19SBen Gras FILE * __restrict);
2382fe8fb19SBen Gras int fscanf(FILE * __restrict, const char * __restrict, ...)
2392fe8fb19SBen Gras __scanflike(2, 3);
2402fe8fb19SBen Gras int fseek(FILE *, long, int);
2412fe8fb19SBen Gras long ftell(FILE *);
2422fe8fb19SBen Gras size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
2432fe8fb19SBen Gras int getc(FILE *);
2442fe8fb19SBen Gras int getchar(void);
2452fe8fb19SBen Gras void perror(const char *);
2462fe8fb19SBen Gras int printf(const char * __restrict, ...)
2472fe8fb19SBen Gras __printflike(1, 2);
2482fe8fb19SBen Gras int putc(int, FILE *);
2492fe8fb19SBen Gras int putchar(int);
2502fe8fb19SBen Gras int puts(const char *);
2512fe8fb19SBen Gras int remove(const char *);
2522fe8fb19SBen Gras void rewind(FILE *);
2532fe8fb19SBen Gras int scanf(const char * __restrict, ...)
2542fe8fb19SBen Gras __scanflike(1, 2);
2552fe8fb19SBen Gras void setbuf(FILE * __restrict, char * __restrict);
2562fe8fb19SBen Gras int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
2572fe8fb19SBen Gras int sscanf(const char * __restrict, const char * __restrict, ...)
2582fe8fb19SBen Gras __scanflike(2, 3);
2592fe8fb19SBen Gras FILE *tmpfile(void);
2602fe8fb19SBen Gras int ungetc(int, FILE *);
261f14fb602SLionel Sambuc int vfprintf(FILE * __restrict, const char * __restrict, __va_list)
2622fe8fb19SBen Gras __printflike(2, 0);
263f14fb602SLionel Sambuc int vprintf(const char * __restrict, __va_list)
2642fe8fb19SBen Gras __printflike(1, 0);
2652fe8fb19SBen Gras
2662fe8fb19SBen Gras #ifndef __AUDIT__
2672fe8fb19SBen Gras char *gets(char *);
2682fe8fb19SBen Gras int sprintf(char * __restrict, const char * __restrict, ...)
2692fe8fb19SBen Gras __printflike(2, 3);
2702fe8fb19SBen Gras char *tmpnam(char *);
2712fe8fb19SBen Gras int vsprintf(char * __restrict, const char * __restrict,
272f14fb602SLionel Sambuc __va_list)
2732fe8fb19SBen Gras __printflike(2, 0);
2742fe8fb19SBen Gras #endif
2752fe8fb19SBen Gras
276e9e08defSLionel Sambuc #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
2772fe8fb19SBen Gras int rename (const char *, const char *) __RENAME(__posix_rename);
2782fe8fb19SBen Gras #else
2792fe8fb19SBen Gras int rename (const char *, const char *);
2802fe8fb19SBen Gras #endif
2812fe8fb19SBen Gras __END_DECLS
2822fe8fb19SBen Gras
283f14fb602SLionel Sambuc #ifndef __LIBC12_SOURCE__
284f14fb602SLionel Sambuc int fgetpos(FILE * __restrict, fpos_t * __restrict) __RENAME(__fgetpos50);
285f14fb602SLionel Sambuc int fsetpos(FILE *, const fpos_t *) __RENAME(__fsetpos50);
286f14fb602SLionel Sambuc #endif
2872fe8fb19SBen Gras /*
2882fe8fb19SBen Gras * IEEE Std 1003.1-90
2892fe8fb19SBen Gras */
2902fe8fb19SBen Gras #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
2912fe8fb19SBen Gras defined(_NETBSD_SOURCE)
2922fe8fb19SBen Gras #define L_ctermid 1024 /* size for ctermid(); PATH_MAX */
2932fe8fb19SBen Gras #define L_cuserid 9 /* size for cuserid(); UT_NAMESIZE + 1 */
2942fe8fb19SBen Gras
2952fe8fb19SBen Gras __BEGIN_DECLS
2962fe8fb19SBen Gras char *ctermid(char *);
2972fe8fb19SBen Gras #ifndef __CUSERID_DECLARED
2982fe8fb19SBen Gras #define __CUSERID_DECLARED
2992fe8fb19SBen Gras /* also declared in unistd.h */
3002fe8fb19SBen Gras char *cuserid(char *);
3012fe8fb19SBen Gras #endif /* __CUSERID_DECLARED */
3022fe8fb19SBen Gras FILE *fdopen(int, const char *);
3032fe8fb19SBen Gras int fileno(FILE *);
3042fe8fb19SBen Gras __END_DECLS
3052fe8fb19SBen Gras #endif /* not ANSI */
3062fe8fb19SBen Gras
3072fe8fb19SBen Gras /*
3082fe8fb19SBen Gras * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
3092fe8fb19SBen Gras */
3102fe8fb19SBen Gras #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
3112fe8fb19SBen Gras defined(_REENTRANT) || defined(_NETBSD_SOURCE)
3122fe8fb19SBen Gras __BEGIN_DECLS
3132fe8fb19SBen Gras void flockfile(FILE *);
3142fe8fb19SBen Gras int ftrylockfile(FILE *);
3152fe8fb19SBen Gras void funlockfile(FILE *);
3162fe8fb19SBen Gras int getc_unlocked(FILE *);
3172fe8fb19SBen Gras int getchar_unlocked(void);
3182fe8fb19SBen Gras int putc_unlocked(int, FILE *);
3192fe8fb19SBen Gras int putchar_unlocked(int);
3202fe8fb19SBen Gras __END_DECLS
3212fe8fb19SBen Gras #endif /* _POSIX_C_SOURCE >= 1995056 || _XOPEN_SOURCE >= 500 || ... */
3222fe8fb19SBen Gras
3232fe8fb19SBen Gras /*
3242fe8fb19SBen Gras * Functions defined in POSIX 1003.2 and XPG2 or later.
3252fe8fb19SBen Gras */
3262fe8fb19SBen Gras #if (_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 2 || \
3272fe8fb19SBen Gras defined(_NETBSD_SOURCE)
3282fe8fb19SBen Gras __BEGIN_DECLS
3292fe8fb19SBen Gras int pclose(FILE *);
3302fe8fb19SBen Gras FILE *popen(const char *, const char *);
3312fe8fb19SBen Gras __END_DECLS
3322fe8fb19SBen Gras #endif
333*0a6a1f1dSLionel Sambuc #ifdef _NETBSD_SOURCE
334*0a6a1f1dSLionel Sambuc __BEGIN_DECLS
335*0a6a1f1dSLionel Sambuc FILE *popenve(const char *, char *const *, char *const *, const char *);
336*0a6a1f1dSLionel Sambuc __END_DECLS
337*0a6a1f1dSLionel Sambuc #endif
3382fe8fb19SBen Gras
3392fe8fb19SBen Gras /*
3402fe8fb19SBen Gras * Functions defined in ISO XPG4.2, ISO C99, POSIX 1003.1-2001 or later.
3412fe8fb19SBen Gras */
3422fe8fb19SBen Gras #if ((__STDC_VERSION__ - 0) >= 199901L) || \
3432fe8fb19SBen Gras ((_POSIX_C_SOURCE - 0) >= 200112L) || \
3442fe8fb19SBen Gras (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
3452fe8fb19SBen Gras ((_XOPEN_SOURCE - 0) >= 500) || \
3462fe8fb19SBen Gras defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
3472fe8fb19SBen Gras __BEGIN_DECLS
3482fe8fb19SBen Gras int snprintf(char * __restrict, size_t, const char * __restrict, ...)
3492fe8fb19SBen Gras __printflike(3, 4);
3502fe8fb19SBen Gras int vsnprintf(char * __restrict, size_t, const char * __restrict,
351f14fb602SLionel Sambuc __va_list)
3522fe8fb19SBen Gras __printflike(3, 0);
3532fe8fb19SBen Gras __END_DECLS
3542fe8fb19SBen Gras #endif
3552fe8fb19SBen Gras
3562fe8fb19SBen Gras /*
3572fe8fb19SBen Gras * Functions defined in XPG4.2.
3582fe8fb19SBen Gras */
3592fe8fb19SBen Gras #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
3602fe8fb19SBen Gras __BEGIN_DECLS
3612fe8fb19SBen Gras int getw(FILE *);
3622fe8fb19SBen Gras int putw(int, FILE *);
3632fe8fb19SBen Gras
3642fe8fb19SBen Gras #ifndef __AUDIT__
3652fe8fb19SBen Gras char *tempnam(const char *, const char *);
3662fe8fb19SBen Gras #endif
3672fe8fb19SBen Gras __END_DECLS
3682fe8fb19SBen Gras #endif
3692fe8fb19SBen Gras
3702fe8fb19SBen Gras /*
3712fe8fb19SBen Gras * X/Open CAE Specification Issue 5 Version 2
3722fe8fb19SBen Gras */
373*0a6a1f1dSLionel Sambuc #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 500 || \
3742fe8fb19SBen Gras defined(_NETBSD_SOURCE)
3752fe8fb19SBen Gras #ifndef off_t
3762fe8fb19SBen Gras typedef __off_t off_t;
3772fe8fb19SBen Gras #define off_t __off_t
3782fe8fb19SBen Gras #endif /* off_t */
3792fe8fb19SBen Gras
3802fe8fb19SBen Gras __BEGIN_DECLS
3812fe8fb19SBen Gras int fseeko(FILE *, off_t, int);
3822fe8fb19SBen Gras off_t ftello(FILE *);
3832fe8fb19SBen Gras __END_DECLS
384*0a6a1f1dSLionel Sambuc #endif /* (_POSIX_C_SOURCE - 0) >= 200112L || _XOPEN_SOURCE >= 500 || ... */
3852fe8fb19SBen Gras
3862fe8fb19SBen Gras /*
3872fe8fb19SBen Gras * Functions defined in ISO C99. Still put under _NETBSD_SOURCE due to
3882fe8fb19SBen Gras * backward compatible.
3892fe8fb19SBen Gras */
3902fe8fb19SBen Gras #if defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)
3912fe8fb19SBen Gras __BEGIN_DECLS
392f14fb602SLionel Sambuc int vscanf(const char * __restrict, __va_list)
3932fe8fb19SBen Gras __scanflike(1, 0);
394f14fb602SLionel Sambuc int vfscanf(FILE * __restrict, const char * __restrict, __va_list)
3952fe8fb19SBen Gras __scanflike(2, 0);
3962fe8fb19SBen Gras int vsscanf(const char * __restrict, const char * __restrict,
397f14fb602SLionel Sambuc __va_list)
3982fe8fb19SBen Gras __scanflike(2, 0);
3992fe8fb19SBen Gras __END_DECLS
4002fe8fb19SBen Gras #endif /* _ISOC99_SOURCE || _NETBSD_SOURCE */
4012fe8fb19SBen Gras
4022fe8fb19SBen Gras /*
4032fe8fb19SBen Gras * Routines that are purely local.
4042fe8fb19SBen Gras */
4052fe8fb19SBen Gras #if defined(_NETBSD_SOURCE)
4062fe8fb19SBen Gras
4072fe8fb19SBen Gras #define FPARSELN_UNESCESC 0x01
4082fe8fb19SBen Gras #define FPARSELN_UNESCCONT 0x02
4092fe8fb19SBen Gras #define FPARSELN_UNESCCOMM 0x04
4102fe8fb19SBen Gras #define FPARSELN_UNESCREST 0x08
4112fe8fb19SBen Gras #define FPARSELN_UNESCALL 0x0f
4122fe8fb19SBen Gras
4132fe8fb19SBen Gras __BEGIN_DECLS
4142fe8fb19SBen Gras int asprintf(char ** __restrict, const char * __restrict, ...)
4152fe8fb19SBen Gras __printflike(2, 3);
4162fe8fb19SBen Gras char *fgetln(FILE * __restrict, size_t * __restrict);
4172fe8fb19SBen Gras char *fparseln(FILE *, size_t *, size_t *, const char[3], int);
4182fe8fb19SBen Gras int fpurge(FILE *);
4192fe8fb19SBen Gras void setbuffer(FILE *, char *, int);
4202fe8fb19SBen Gras int setlinebuf(FILE *);
4212fe8fb19SBen Gras int vasprintf(char ** __restrict, const char * __restrict,
422f14fb602SLionel Sambuc __va_list)
4232fe8fb19SBen Gras __printflike(2, 0);
4242fe8fb19SBen Gras const char *fmtcheck(const char *, const char *)
4252fe8fb19SBen Gras __format_arg(2);
4262fe8fb19SBen Gras __END_DECLS
4272fe8fb19SBen Gras
4282fe8fb19SBen Gras /*
4292fe8fb19SBen Gras * Stdio function-access interface.
4302fe8fb19SBen Gras */
4312fe8fb19SBen Gras __BEGIN_DECLS
4322fe8fb19SBen Gras FILE *funopen(const void *,
4332fe8fb19SBen Gras int (*)(void *, char *, int),
4342fe8fb19SBen Gras int (*)(void *, const char *, int),
435f14fb602SLionel Sambuc off_t (*)(void *, off_t, int),
436f14fb602SLionel Sambuc int (*)(void *));
437f14fb602SLionel Sambuc FILE *funopen2(const void *,
438f14fb602SLionel Sambuc ssize_t (*)(void *, void *, size_t),
439f14fb602SLionel Sambuc ssize_t (*)(void *, const void *, size_t),
440f14fb602SLionel Sambuc off_t (*)(void *, off_t, int),
441f14fb602SLionel Sambuc int (*)(void *),
4422fe8fb19SBen Gras int (*)(void *));
4432fe8fb19SBen Gras __END_DECLS
4442fe8fb19SBen Gras #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
4452fe8fb19SBen Gras #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
446f14fb602SLionel Sambuc #define fropen2(cookie, fn) funopen2(cookie, fn, 0, 0, 0, 0)
447f14fb602SLionel Sambuc #define fwopen2(cookie, fn) funopen2(cookie, 0, fn, 0, 0, 0)
4482fe8fb19SBen Gras #endif /* _NETBSD_SOURCE */
4492fe8fb19SBen Gras
4502fe8fb19SBen Gras /*
4512fe8fb19SBen Gras * Functions internal to the implementation.
4522fe8fb19SBen Gras */
4532fe8fb19SBen Gras __BEGIN_DECLS
4542fe8fb19SBen Gras int __srget(FILE *);
4552fe8fb19SBen Gras int __swbuf(int, FILE *);
4562fe8fb19SBen Gras __END_DECLS
4572fe8fb19SBen Gras
4582fe8fb19SBen Gras /*
4592fe8fb19SBen Gras * The __sfoo macros are here so that we can
4602fe8fb19SBen Gras * define function versions in the C library.
4612fe8fb19SBen Gras */
4622fe8fb19SBen Gras #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
4632fe8fb19SBen Gras #if defined(__GNUC__) && defined(__STDC__)
__sputc(int _c,FILE * _p)4642fe8fb19SBen Gras static __inline int __sputc(int _c, FILE *_p) {
4652fe8fb19SBen Gras if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
466*0a6a1f1dSLionel Sambuc return *_p->_p++ = (unsigned char)_c;
4672fe8fb19SBen Gras else
468*0a6a1f1dSLionel Sambuc return __swbuf(_c, _p);
4692fe8fb19SBen Gras }
4702fe8fb19SBen Gras #else
4712fe8fb19SBen Gras /*
4722fe8fb19SBen Gras * This has been tuned to generate reasonable code on the vax using pcc.
4732fe8fb19SBen Gras */
4742fe8fb19SBen Gras #define __sputc(c, p) \
4752fe8fb19SBen Gras (--(p)->_w < 0 ? \
4762fe8fb19SBen Gras (p)->_w >= (p)->_lbfsize ? \
4772fe8fb19SBen Gras (*(p)->_p = (c)), *(p)->_p != '\n' ? \
4782fe8fb19SBen Gras (int)*(p)->_p++ : \
4792fe8fb19SBen Gras __swbuf('\n', p) : \
4802fe8fb19SBen Gras __swbuf((int)(c), p) : \
4812fe8fb19SBen Gras (*(p)->_p = (c), (int)*(p)->_p++))
4822fe8fb19SBen Gras #endif
4832fe8fb19SBen Gras
4842fe8fb19SBen Gras #define __sfeof(p) (((p)->_flags & __SEOF) != 0)
4852fe8fb19SBen Gras #define __sferror(p) (((p)->_flags & __SERR) != 0)
4862fe8fb19SBen Gras #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
4872fe8fb19SBen Gras #define __sfileno(p) \
4882fe8fb19SBen Gras ((p)->_file == -1 ? -1 : (int)(unsigned short)(p)->_file)
4892fe8fb19SBen Gras
49084d9c625SLionel Sambuc #if !defined(__lint__) && !defined(__cplusplus)
4912fe8fb19SBen Gras #if !defined(_REENTRANT) && !defined(_PTHREADS)
4922fe8fb19SBen Gras #define feof(p) __sfeof(p)
4932fe8fb19SBen Gras #define ferror(p) __sferror(p)
4942fe8fb19SBen Gras #define clearerr(p) __sclearerr(p)
4952fe8fb19SBen Gras
4962fe8fb19SBen Gras #define getc(fp) __sgetc(fp)
4972fe8fb19SBen Gras #define putc(x, fp) __sputc(x, fp)
4982fe8fb19SBen Gras #endif /* !_REENTRANT && !_PTHREADS */
4992fe8fb19SBen Gras
5002fe8fb19SBen Gras #define getchar() getc(stdin)
5012fe8fb19SBen Gras #define putchar(x) putc(x, stdout)
5022fe8fb19SBen Gras
50384d9c625SLionel Sambuc #endif /* !__lint__ && !__cplusplus */
50484d9c625SLionel Sambuc
50584d9c625SLionel Sambuc #if (defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
50684d9c625SLionel Sambuc defined(_NETBSD_SOURCE)) && !defined(__cplusplus)
5072fe8fb19SBen Gras #if !defined(_REENTRANT) && !defined(_PTHREADS)
5082fe8fb19SBen Gras #define fileno(p) __sfileno(p)
5092fe8fb19SBen Gras #endif /* !_REENTRANT && !_PTHREADS */
51084d9c625SLionel Sambuc #endif /* !_ANSI_SOURCE && !__cplusplus*/
5112fe8fb19SBen Gras
5122fe8fb19SBen Gras #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
513*0a6a1f1dSLionel Sambuc __BEGIN_DECLS
514f14fb602SLionel Sambuc int vdprintf(int, const char * __restrict, __va_list)
5152fe8fb19SBen Gras __printflike(2, 0);
5162fe8fb19SBen Gras int dprintf(int, const char * __restrict, ...)
5172fe8fb19SBen Gras __printflike(2, 3);
518*0a6a1f1dSLionel Sambuc __END_DECLS
5192fe8fb19SBen Gras #endif /* (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE) */
5202fe8fb19SBen Gras
5212fe8fb19SBen Gras #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
52284d9c625SLionel Sambuc defined(_REENTRANT) || defined(_NETBSD_SOURCE) && !defined(__cplusplus)
5232fe8fb19SBen Gras #define getc_unlocked(fp) __sgetc(fp)
5242fe8fb19SBen Gras #define putc_unlocked(x, fp) __sputc(x, fp)
5252fe8fb19SBen Gras
5262fe8fb19SBen Gras #define getchar_unlocked() getc_unlocked(stdin)
5272fe8fb19SBen Gras #define putchar_unlocked(x) putc_unlocked(x, stdout)
5282fe8fb19SBen Gras #endif /* _POSIX_C_SOURCE >= 199506 || _XOPEN_SOURCE >= 500 || _REENTRANT... */
5292fe8fb19SBen Gras
5302fe8fb19SBen Gras #if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \
5312fe8fb19SBen Gras defined(_NETBSD_SOURCE)
532*0a6a1f1dSLionel Sambuc __BEGIN_DECLS
5332fe8fb19SBen Gras FILE *fmemopen(void * __restrict, size_t, const char * __restrict);
534*0a6a1f1dSLionel Sambuc FILE *open_memstream(char **, size_t *);
535*0a6a1f1dSLionel Sambuc ssize_t getdelim(char ** __restrict, size_t * __restrict, int,
536*0a6a1f1dSLionel Sambuc FILE * __restrict);
537*0a6a1f1dSLionel Sambuc ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict);
538*0a6a1f1dSLionel Sambuc __END_DECLS
5392fe8fb19SBen Gras #endif
5402fe8fb19SBen Gras
54184d9c625SLionel Sambuc #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
54284d9c625SLionel Sambuc # ifndef __LOCALE_T_DECLARED
54384d9c625SLionel Sambuc typedef struct _locale *locale_t;
54484d9c625SLionel Sambuc # define __LOCALE_T_DECLARED
54584d9c625SLionel Sambuc # endif
54684d9c625SLionel Sambuc __BEGIN_DECLS
54784d9c625SLionel Sambuc int fprintf_l(FILE * __restrict, locale_t, const char * __restrict, ...)
54884d9c625SLionel Sambuc __printflike(3, 4);
54984d9c625SLionel Sambuc int vfprintf_l(FILE * __restrict, locale_t, const char * __restrict,
55084d9c625SLionel Sambuc __va_list) __printflike(3, 0);
55184d9c625SLionel Sambuc int printf_l(locale_t, const char * __restrict, ...)
55284d9c625SLionel Sambuc __printflike(2, 3);
55384d9c625SLionel Sambuc int vprintf_l(locale_t, const char * __restrict, __va_list)
55484d9c625SLionel Sambuc __printflike(2, 0);
55584d9c625SLionel Sambuc int asprintf_l(char ** __restrict, locale_t, const char * __restrict, ...)
55684d9c625SLionel Sambuc __printflike(3, 4);
55784d9c625SLionel Sambuc int vasprintf_l(char ** __restrict, locale_t, const char * __restrict,
55884d9c625SLionel Sambuc __va_list)
55984d9c625SLionel Sambuc __printflike(3, 0);
56084d9c625SLionel Sambuc int vdprintf_l(int, locale_t, const char * __restrict, __va_list)
56184d9c625SLionel Sambuc __printflike(3, 0);
56284d9c625SLionel Sambuc int dprintf_l(int, locale_t, const char * __restrict, ...)
56384d9c625SLionel Sambuc __printflike(3, 4);
56484d9c625SLionel Sambuc int snprintf_l(char * __restrict, size_t, locale_t,
56584d9c625SLionel Sambuc const char * __restrict, ...) __printflike(4, 5);
56684d9c625SLionel Sambuc int vsnprintf_l(char * __restrict, size_t, locale_t,
56784d9c625SLionel Sambuc const char * __restrict, __va_list) __printflike(4, 0);
56884d9c625SLionel Sambuc #ifndef __AUDIT__
56984d9c625SLionel Sambuc int sprintf_l(char * __restrict, locale_t, const char * __restrict, ...)
57084d9c625SLionel Sambuc __printflike(3, 4);
57184d9c625SLionel Sambuc int vsprintf_l(char * __restrict, locale_t, const char * __restrict,
57284d9c625SLionel Sambuc __va_list) __printflike(3, 0);
57384d9c625SLionel Sambuc #endif
57484d9c625SLionel Sambuc
57584d9c625SLionel Sambuc int fscanf_l(FILE * __restrict, locale_t, const char * __restrict, ...)
57684d9c625SLionel Sambuc __scanflike(3, 4);
57784d9c625SLionel Sambuc int scanf_l(locale_t, const char * __restrict, ...)
57884d9c625SLionel Sambuc __scanflike(2, 3);
57984d9c625SLionel Sambuc int sscanf_l(const char * __restrict, locale_t,
58084d9c625SLionel Sambuc const char * __restrict, ...) __scanflike(3, 4);
58184d9c625SLionel Sambuc int vscanf_l(locale_t, const char * __restrict, __va_list)
58284d9c625SLionel Sambuc __scanflike(2, 0);
58384d9c625SLionel Sambuc int vfscanf_l(FILE * __restrict, locale_t, const char * __restrict,
58484d9c625SLionel Sambuc __va_list) __scanflike(3, 0);
58584d9c625SLionel Sambuc int vsscanf_l(const char * __restrict, locale_t, const char * __restrict,
58684d9c625SLionel Sambuc __va_list) __scanflike(3, 0);
58784d9c625SLionel Sambuc #ifdef _NETBSD_SOURCE
58884d9c625SLionel Sambuc int snprintf_ss(char *restrict, size_t, const char * __restrict, ...)
58984d9c625SLionel Sambuc __printflike(3, 4);
59084d9c625SLionel Sambuc int vsnprintf_ss(char *restrict, size_t, const char * __restrict, __va_list)
59184d9c625SLionel Sambuc __printflike(3, 0);
59284d9c625SLionel Sambuc #endif
59384d9c625SLionel Sambuc __END_DECLS
59484d9c625SLionel Sambuc #endif
59584d9c625SLionel Sambuc
5962fe8fb19SBen Gras #if _FORTIFY_SOURCE > 0
5972fe8fb19SBen Gras #include <ssp/stdio.h>
5982fe8fb19SBen Gras #endif
5992fe8fb19SBen Gras
6002fe8fb19SBen Gras #endif /* _STDIO_H_ */
601