xref: /netbsd-src/include/stdio.h (revision f64856e518031b6f08d512a193f18b17abf4710f)
1*f64856e5Srillig /*	$NetBSD: stdio.h,v 1.104 2021/09/11 20:05:33 rillig Exp $	*/
24d2cbfceScgd 
361f28255Scgd /*-
4b7b7322cSperry  * Copyright (c) 1990, 1993
5b7b7322cSperry  *	The Regents of the University of California.  All rights reserved.
661f28255Scgd  *
761f28255Scgd  * This code is derived from software contributed to Berkeley by
861f28255Scgd  * Chris Torek.
961f28255Scgd  *
1061f28255Scgd  * Redistribution and use in source and binary forms, with or without
1161f28255Scgd  * modification, are permitted provided that the following conditions
1261f28255Scgd  * are met:
1361f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1461f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1561f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1661f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1761f28255Scgd  *    documentation and/or other materials provided with the distribution.
18039cc956Sagc  * 3. Neither the name of the University nor the names of its contributors
1961f28255Scgd  *    may be used to endorse or promote products derived from this software
2061f28255Scgd  *    without specific prior written permission.
2161f28255Scgd  *
2261f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2361f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2461f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2561f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2661f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2761f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2861f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2961f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3061f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3161f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3261f28255Scgd  * SUCH DAMAGE.
3361f28255Scgd  *
34b7b7322cSperry  *	@(#)stdio.h	8.5 (Berkeley) 4/29/95
3561f28255Scgd  */
3661f28255Scgd 
3761f28255Scgd #ifndef	_STDIO_H_
3861f28255Scgd #define	_STDIO_H_
3961f28255Scgd 
4061f28255Scgd #include <sys/cdefs.h>
415d431855Skleink #include <sys/featuretest.h>
42926eae7fSkleink #include <sys/ansi.h>
4361f28255Scgd 
44af730bf1Sjoerg #if (!defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
45af730bf1Sjoerg     !defined(_XOPEN_SOURCE)) || ((_POSIX_C_SOURCE - 0) >= 200809L || \
46af730bf1Sjoerg      defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
47af730bf1Sjoerg      (__cplusplus - 0) >= 201103L || defined(_NETBSD_SOURCE))
48af730bf1Sjoerg #define __STDIO_C99_FEATURES
49af730bf1Sjoerg #endif
50af730bf1Sjoerg 
512922de74Scgd #ifdef	_BSD_SIZE_T_
522922de74Scgd typedef	_BSD_SIZE_T_	size_t;
532922de74Scgd #undef	_BSD_SIZE_T_
5461f28255Scgd #endif
55d4a3cf6aSroy #ifdef	_BSD_SSIZE_T_
56d4a3cf6aSroy typedef	_BSD_SSIZE_T_	ssize_t;
57d4a3cf6aSroy #undef	_BSD_SSIZE_T_
58d4a3cf6aSroy #endif
5961f28255Scgd 
603eb244d8Sjoerg #if defined(_POSIX_C_SOURCE)
613eb244d8Sjoerg #ifndef __VA_LIST_DECLARED
623eb244d8Sjoerg typedef __va_list va_list;
633eb244d8Sjoerg #define __VA_LIST_DECLARED
643eb244d8Sjoerg #endif
653eb244d8Sjoerg #endif
663eb244d8Sjoerg 
671bba558eSkleink #include <sys/null.h>
6861f28255Scgd 
6975431188Scgd typedef struct __sfpos {
709a020528Skleink 	__off_t _pos;
711897181aSchristos 	__mbstate_t _mbstate_in, _mbstate_out;
7275431188Scgd } fpos_t;
7361f28255Scgd 
7461f28255Scgd #define	_FSTDIO			/* Define for new stdio with functions. */
7561f28255Scgd 
7661f28255Scgd /*
7761f28255Scgd  * NB: to fit things in six character monocase externals, the stdio
7861f28255Scgd  * code uses the prefix `__s' for stdio objects, typically followed
7961f28255Scgd  * by a three-character attempt at a mnemonic.
8061f28255Scgd  */
8161f28255Scgd 
8261f28255Scgd /* stdio buffers */
8361f28255Scgd struct __sbuf {
8461f28255Scgd 	unsigned char *_base;
8561f28255Scgd 	int	_size;
8661f28255Scgd };
8761f28255Scgd 
8861f28255Scgd /*
8961f28255Scgd  * stdio state variables.
9061f28255Scgd  *
9161f28255Scgd  * The following always hold:
9261f28255Scgd  *
9361f28255Scgd  *	if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
9461f28255Scgd  *		_lbfsize is -_bf._size, else _lbfsize is 0
9561f28255Scgd  *	if _flags&__SRD, _w is 0
9661f28255Scgd  *	if _flags&__SWR, _r is 0
9761f28255Scgd  *
9861f28255Scgd  * This ensures that the getc and putc macros (or inline functions) never
9961f28255Scgd  * try to write or read from a file that is in `read' or `write' mode.
10061f28255Scgd  * (Moreover, they can, and do, automatically switch from read mode to
10161f28255Scgd  * write mode, and back, on "r+" and "w+" files.)
10261f28255Scgd  *
10361f28255Scgd  * _lbfsize is used only to make the inline line-buffered output stream
10461f28255Scgd  * code as compact as possible.
10561f28255Scgd  *
1060a201ba3Srillig  * _ub (via _ext and struct __sfileext), _up, and _ur are used when ungetc()
1070a201ba3Srillig  * pushes back more characters than fit in the current _bf, or when ungetc()
1080a201ba3Srillig  * pushes back a character that does not match the previous one in _bf.
1090a201ba3Srillig  * When this happens, _ext._base becomes non-nil (i.e., a stream has ungetc()
1100a201ba3Srillig  * data iff _ub._base != NULL) and _up and _ur save the current values of _p
1110a201ba3Srillig  * and _r.
11261f28255Scgd  */
11361f28255Scgd typedef	struct __sFILE {
11461f28255Scgd 	unsigned char *_p;	/* current position in (some) buffer */
11561f28255Scgd 	int	_r;		/* read space left for getc() */
11661f28255Scgd 	int	_w;		/* write space left for putc() */
1171e468fbfSchristos 	unsigned short _flags;	/* flags, below; this FILE is free if 0 */
11861f28255Scgd 	short	_file;		/* fileno, if Unix descriptor, else -1 */
11961f28255Scgd 	struct	__sbuf _bf;	/* the buffer (at least 1 byte, if !NULL) */
12061f28255Scgd 	int	_lbfsize;	/* 0 or -_bf._size, for inline putc */
12161f28255Scgd 
12261f28255Scgd 	/* operations */
12361f28255Scgd 	void	*_cookie;	/* cookie passed to io functions */
12419b7469aSperry 	int	(*_close)(void *);
1250ed4e38bSchristos 	ssize_t	(*_read) (void *, void *, size_t);
1261897181aSchristos 	__off_t	(*_seek) (void *, __off_t, int);
1270ed4e38bSchristos 	ssize_t	(*_write)(void *, const void *, size_t);
12861f28255Scgd 
12917f3654aSyamt 	/* file extension */
13017f3654aSyamt 	struct	__sbuf _ext;
13117f3654aSyamt 
13261f28255Scgd 	/* separate buffer for long sequences of ungetc() */
13361f28255Scgd 	unsigned char *_up;	/* saved _p when _p is doing ungetc data */
13461f28255Scgd 	int	_ur;		/* saved _r when _r is counting ungetc data */
13561f28255Scgd 
13661f28255Scgd 	/* tricks to meet minimum requirements even when malloc() fails */
13761f28255Scgd 	unsigned char _ubuf[3];	/* guarantee an ungetc() buffer */
13861f28255Scgd 	unsigned char _nbuf[1];	/* guarantee a getc() buffer */
13961f28255Scgd 
1400ed4e38bSchristos 	int	(*_flush)(void *);
14100711901Sjoerg 	/* Formerly used by fgetln/fgetwln; kept for binary compatibility */
1420ed4e38bSchristos 	char	_lb_unused[sizeof(struct __sbuf) - sizeof(int (*)(void *))];
14361f28255Scgd 
14461f28255Scgd 	/* Unix stdio files get aligned to block boundaries on fseek() */
14561f28255Scgd 	int	_blksize;	/* stat.st_blksize (may be != _bf._size) */
1461897181aSchristos 	__off_t	_offset;	/* current lseek offset */
14761f28255Scgd } FILE;
14861f28255Scgd 
14961f28255Scgd __BEGIN_DECLS
150ca5a32edSchristos extern FILE __sF[3];
15161f28255Scgd __END_DECLS
15261f28255Scgd 
15361f28255Scgd #define	__SLBF	0x0001		/* line buffered */
15461f28255Scgd #define	__SNBF	0x0002		/* unbuffered */
15561f28255Scgd #define	__SRD	0x0004		/* OK to read */
15661f28255Scgd #define	__SWR	0x0008		/* OK to write */
15761f28255Scgd 	/* RD and WR are never simultaneously asserted */
15861f28255Scgd #define	__SRW	0x0010		/* open for reading & writing */
15961f28255Scgd #define	__SEOF	0x0020		/* found EOF */
16061f28255Scgd #define	__SERR	0x0040		/* found error */
16161f28255Scgd #define	__SMBF	0x0080		/* _buf is from malloc */
16261f28255Scgd #define	__SAPP	0x0100		/* fdopen()ed in append mode */
16361f28255Scgd #define	__SSTR	0x0200		/* this is an sprintf/snprintf string */
164081e8d71Senami #define	__SOPT	0x0400		/* do fseek() optimization */
165081e8d71Senami #define	__SNPT	0x0800		/* do not do fseek() optimization */
16661f28255Scgd #define	__SOFF	0x1000		/* set iff _offset is in fact correct */
167d5436670Scgd #define	__SMOD	0x2000		/* true => fgetln modified _p text */
168253ef37dSperry #define	__SALC	0x4000		/* allocate string space dynamically */
16961f28255Scgd 
17061f28255Scgd /*
17161f28255Scgd  * The following three definitions are for ANSI C, which took them
17261f28255Scgd  * from System V, which brilliantly took internal interface macros and
17361f28255Scgd  * made them official arguments to setvbuf(), without renaming them.
17461f28255Scgd  * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
17561f28255Scgd  *
17661f28255Scgd  * Although numbered as their counterparts above, the implementation
17761f28255Scgd  * does not rely on this.
17861f28255Scgd  */
17961f28255Scgd #define	_IOFBF	0		/* setvbuf should set fully buffered */
18061f28255Scgd #define	_IOLBF	1		/* setvbuf should set line buffered */
18161f28255Scgd #define	_IONBF	2		/* setvbuf should set unbuffered */
18261f28255Scgd 
18361f28255Scgd #define	BUFSIZ	1024		/* size of buffer used by setbuf */
18461f28255Scgd #define	EOF	(-1)
18561f28255Scgd 
18661f28255Scgd /*
187b7b7322cSperry  * FOPEN_MAX is a minimum maximum, and is the number of streams that
188b7b7322cSperry  * stdio can provide without attempting to allocate further resources
189b7b7322cSperry  * (which could fail).  Do not use this for anything.
19061f28255Scgd  */
191b7b7322cSperry 				/* must be == _POSIX_STREAM_MAX <limits.h> */
19261f28255Scgd #define	FOPEN_MAX	20	/* must be <= OPEN_MAX <sys/syslimits.h> */
19361f28255Scgd #define	FILENAME_MAX	1024	/* must be <= PATH_MAX <sys/syslimits.h> */
19461f28255Scgd 
19561f28255Scgd /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
1969656aaa5Sbjh21 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
197cefdfaf4Smrg #define	P_tmpdir	"/tmp/"
19861f28255Scgd #endif
19961f28255Scgd #define	L_tmpnam	1024	/* XXX must be == PATH_MAX */
20032c802c3Schristos /* Always ensure that this is consistent with <limits.h> */
20132c802c3Schristos #ifndef TMP_MAX
20232c802c3Schristos #define TMP_MAX			308915776	/* Legacy */
20332c802c3Schristos #endif
20461f28255Scgd 
205ff08122eSkleink /* Always ensure that these are consistent with <fcntl.h> and <unistd.h>! */
20661f28255Scgd #ifndef SEEK_SET
20761f28255Scgd #define	SEEK_SET	0	/* set file offset to offset */
20861f28255Scgd #endif
20961f28255Scgd #ifndef SEEK_CUR
21061f28255Scgd #define	SEEK_CUR	1	/* set file offset to current plus offset */
21161f28255Scgd #endif
21261f28255Scgd #ifndef SEEK_END
21361f28255Scgd #define	SEEK_END	2	/* set file offset to EOF plus offset */
21461f28255Scgd #endif
21561f28255Scgd 
21661f28255Scgd #define	stdin	(&__sF[0])
21761f28255Scgd #define	stdout	(&__sF[1])
21861f28255Scgd #define	stderr	(&__sF[2])
21961f28255Scgd 
22061f28255Scgd /*
22161f28255Scgd  * Functions defined in ANSI C standard.
22261f28255Scgd  */
22361f28255Scgd __BEGIN_DECLS
22419b7469aSperry void	 clearerr(FILE *);
22519b7469aSperry int	 fclose(FILE *);
22619b7469aSperry int	 feof(FILE *);
22719b7469aSperry int	 ferror(FILE *);
22819b7469aSperry int	 fflush(FILE *);
22919b7469aSperry int	 fgetc(FILE *);
23019b7469aSperry char	*fgets(char * __restrict, int, FILE * __restrict);
23113034da9Skleink FILE	*fopen(const char * __restrict , const char * __restrict);
2329fa41d73Schristos int	 fprintf(FILE * __restrict, const char * __restrict, ...)
2338a601553Sjoerg 		__printflike(2, 3);
23419b7469aSperry int	 fputc(int, FILE *);
23519b7469aSperry int	 fputs(const char * __restrict, FILE * __restrict);
23619b7469aSperry size_t	 fread(void * __restrict, size_t, size_t, FILE * __restrict);
23713034da9Skleink FILE	*freopen(const char * __restrict, const char * __restrict,
23813034da9Skleink 	    FILE * __restrict);
2399fa41d73Schristos int	 fscanf(FILE * __restrict, const char * __restrict, ...)
2408a601553Sjoerg 		__scanflike(2, 3);
24119b7469aSperry int	 fseek(FILE *, long, int);
24219b7469aSperry long	 ftell(FILE *);
24319b7469aSperry size_t	 fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
24419b7469aSperry int	 getc(FILE *);
24519b7469aSperry int	 getchar(void);
24619b7469aSperry void	 perror(const char *);
2479fa41d73Schristos int	 printf(const char * __restrict, ...)
2488a601553Sjoerg 		__printflike(1, 2);
24919b7469aSperry int	 putc(int, FILE *);
25019b7469aSperry int	 putchar(int);
25119b7469aSperry int	 puts(const char *);
25219b7469aSperry int	 remove(const char *);
25319b7469aSperry void	 rewind(FILE *);
2549fa41d73Schristos int	 scanf(const char * __restrict, ...)
2558a601553Sjoerg 		__scanflike(1, 2);
25619b7469aSperry void	 setbuf(FILE * __restrict, char * __restrict);
25719b7469aSperry int	 setvbuf(FILE * __restrict, char * __restrict, int, size_t);
2589fa41d73Schristos int	 sscanf(const char * __restrict, const char * __restrict, ...)
2598a601553Sjoerg 		__scanflike(2, 3);
26019b7469aSperry FILE	*tmpfile(void);
26119b7469aSperry int	 ungetc(int, FILE *);
2623eb244d8Sjoerg int	 vfprintf(FILE * __restrict, const char * __restrict, __va_list)
2638a601553Sjoerg 		__printflike(2, 0);
2643eb244d8Sjoerg int	 vprintf(const char * __restrict, __va_list)
2658a601553Sjoerg 		__printflike(1, 0);
266ab22ce8dSmycroft 
267ab22ce8dSmycroft #ifndef __AUDIT__
26819b7469aSperry char	*gets(char *);
2699fa41d73Schristos int	 sprintf(char * __restrict, const char * __restrict, ...)
2708a601553Sjoerg 		__printflike(2, 3);
27119b7469aSperry char	*tmpnam(char *);
27219b7469aSperry int	 vsprintf(char * __restrict, const char * __restrict,
2733eb244d8Sjoerg     __va_list)
2748a601553Sjoerg 		__printflike(2, 0);
275ab22ce8dSmycroft #endif
2765d431855Skleink 
2775d431855Skleink #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
27819b7469aSperry int	 rename (const char *, const char *) __RENAME(__posix_rename);
2795d431855Skleink #else
28019b7469aSperry int	 rename (const char *, const char *);
2815d431855Skleink #endif
28261f28255Scgd __END_DECLS
28361f28255Scgd 
2841897181aSchristos #ifndef __LIBC12_SOURCE__
2851897181aSchristos int	 fgetpos(FILE * __restrict, fpos_t * __restrict) __RENAME(__fgetpos50);
2861897181aSchristos int	 fsetpos(FILE *, const fpos_t *) __RENAME(__fsetpos50);
2871897181aSchristos #endif
28861f28255Scgd /*
289cc46a13dSkleink  * IEEE Std 1003.1-90
29061f28255Scgd  */
2914be7a2dcSbjh21 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
2924be7a2dcSbjh21     defined(_NETBSD_SOURCE)
29361f28255Scgd #define	L_ctermid	1024	/* size for ctermid(); PATH_MAX */
2949a6746f2Sjtc #define L_cuserid	9	/* size for cuserid(); UT_NAMESIZE + 1 */
29561f28255Scgd 
29661f28255Scgd __BEGIN_DECLS
29719b7469aSperry char	*ctermid(char *);
2988939b770Schristos #ifndef __CUSERID_DECLARED
2998939b770Schristos #define __CUSERID_DECLARED
3008939b770Schristos /* also declared in unistd.h */
30119b7469aSperry char	*cuserid(char *);
3028939b770Schristos #endif /* __CUSERID_DECLARED */
30319b7469aSperry FILE	*fdopen(int, const char *);
30419b7469aSperry int	 fileno(FILE *);
30561f28255Scgd __END_DECLS
30661f28255Scgd #endif /* not ANSI */
30761f28255Scgd 
308cc46a13dSkleink /*
309cc46a13dSkleink  * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
310cc46a13dSkleink  */
311af730bf1Sjoerg #if defined(__STDIO_C99_FEATURES) || (_POSIX_C_SOURCE - 0) >= 199506L || \
312af730bf1Sjoerg     (_XOPEN_SOURCE - 0) >= 500 || defined(_REENTRANT)
313cc46a13dSkleink __BEGIN_DECLS
31419b7469aSperry void	flockfile(FILE *);
31519b7469aSperry int	ftrylockfile(FILE *);
31619b7469aSperry void	funlockfile(FILE *);
31719b7469aSperry int	getc_unlocked(FILE *);
31819b7469aSperry int	getchar_unlocked(void);
31919b7469aSperry int	putc_unlocked(int, FILE *);
32019b7469aSperry int	putchar_unlocked(int);
321cc46a13dSkleink __END_DECLS
322d27ba004Srillig #endif /* C99 || _POSIX_C_SOURCE >= 199506 || _XOPEN_SOURCE >= 500 || ... */
323397b763dSjtc 
32461f28255Scgd /*
325cc46a13dSkleink  * Functions defined in POSIX 1003.2 and XPG2 or later.
32661f28255Scgd  */
3274be7a2dcSbjh21 #if (_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 2 || \
3284be7a2dcSbjh21     defined(_NETBSD_SOURCE)
32961f28255Scgd __BEGIN_DECLS
33019b7469aSperry int	 pclose(FILE *);
33119b7469aSperry FILE	*popen(const char *, const char *);
332ff08122eSkleink __END_DECLS
333ff08122eSkleink #endif
334829f81acSchristos #ifdef _NETBSD_SOURCE
33572566f3fSchristos __BEGIN_DECLS
336829f81acSchristos FILE	*popenve(const char *, char *const *, char *const *, const char *);
33772566f3fSchristos __END_DECLS
338829f81acSchristos #endif
339ff08122eSkleink 
340ff08122eSkleink /*
34116f5958bSrillig  * Functions defined in XPG4.2, ISO C99, POSIX 1003.1-2001 or later.
342691c56aaSkleink  */
343af730bf1Sjoerg #if defined(__STDIO_C99_FEATURES) || (_POSIX_C_SOURCE - 0) >= 200112L || \
344691c56aaSkleink     (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
345af730bf1Sjoerg     (_XOPEN_SOURCE - 0) >= 500
3469f88f122Smrg __BEGIN_DECLS
347691c56aaSkleink int	 snprintf(char * __restrict, size_t, const char * __restrict, ...)
3488a601553Sjoerg 		__printflike(3, 4);
349691c56aaSkleink int	 vsnprintf(char * __restrict, size_t, const char * __restrict,
3503eb244d8Sjoerg 	    __va_list)
3518a601553Sjoerg 		__printflike(3, 0);
3529f88f122Smrg __END_DECLS
353691c56aaSkleink #endif
354691c56aaSkleink 
355691c56aaSkleink /*
356ff08122eSkleink  * Functions defined in XPG4.2.
357ff08122eSkleink  */
3584be7a2dcSbjh21 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
359ff08122eSkleink __BEGIN_DECLS
36019b7469aSperry int	 getw(FILE *);
36119b7469aSperry int	 putw(int, FILE *);
362ab22ce8dSmycroft 
363ab22ce8dSmycroft #ifndef __AUDIT__
36419b7469aSperry char	*tempnam(const char *, const char *);
365ab22ce8dSmycroft #endif
366ff08122eSkleink __END_DECLS
367ff08122eSkleink #endif
368ff08122eSkleink 
369ff08122eSkleink /*
370dae36061Skleink  * X/Open CAE Specification Issue 5 Version 2
371dae36061Skleink  */
372fc5db8c0Swiz #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 500 || \
3734be7a2dcSbjh21     defined(_NETBSD_SOURCE)
374dae36061Skleink #ifndef	off_t
375dae36061Skleink typedef	__off_t		off_t;
37611ecb446Skleink #define	off_t		__off_t
3777f133420Sdrochner #endif /* off_t */
378dae36061Skleink 
379081e8d71Senami __BEGIN_DECLS
38019b7469aSperry int	 fseeko(FILE *, off_t, int);
38119b7469aSperry off_t	 ftello(FILE *);
382081e8d71Senami __END_DECLS
383fc5db8c0Swiz #endif /* (_POSIX_C_SOURCE - 0) >= 200112L || _XOPEN_SOURCE >= 500 || ... */
384dae36061Skleink 
385dae36061Skleink /*
386*f64856e5Srillig  * Functions defined in ISO C99.
387e90b0847Smatt  */
388af730bf1Sjoerg #if defined(__STDIO_C99_FEATURES)
389e90b0847Smatt __BEGIN_DECLS
3903eb244d8Sjoerg int	 vscanf(const char * __restrict, __va_list)
3918a601553Sjoerg 		__scanflike(1, 0);
3923eb244d8Sjoerg int	 vfscanf(FILE * __restrict, const char * __restrict, __va_list)
3938a601553Sjoerg 		__scanflike(2, 0);
394e90b0847Smatt int	 vsscanf(const char * __restrict, const char * __restrict,
3953eb244d8Sjoerg     __va_list)
3968a601553Sjoerg     __scanflike(2, 0);
397e90b0847Smatt __END_DECLS
398af730bf1Sjoerg #endif /* C99 */
399e90b0847Smatt 
400e90b0847Smatt /*
401ff08122eSkleink  * Routines that are purely local.
402ff08122eSkleink  */
4034be7a2dcSbjh21 #if defined(_NETBSD_SOURCE)
404b1e79510Slukem 
405b1e79510Slukem #define	FPARSELN_UNESCESC	0x01
406b1e79510Slukem #define	FPARSELN_UNESCCONT	0x02
407b1e79510Slukem #define	FPARSELN_UNESCCOMM	0x04
408b1e79510Slukem #define	FPARSELN_UNESCREST	0x08
409b1e79510Slukem #define	FPARSELN_UNESCALL	0x0f
410b1e79510Slukem 
411ff08122eSkleink __BEGIN_DECLS
41219b7469aSperry int	 asprintf(char ** __restrict, const char * __restrict, ...)
4138a601553Sjoerg 		__printflike(2, 3);
41419b7469aSperry char	*fgetln(FILE * __restrict, size_t * __restrict);
415b1e79510Slukem char	*fparseln(FILE *, size_t *, size_t *, const char[3], int);
41619b7469aSperry int	 fpurge(FILE *);
41719b7469aSperry void	 setbuffer(FILE *, char *, int);
41819b7469aSperry int	 setlinebuf(FILE *);
41919b7469aSperry int	 vasprintf(char ** __restrict, const char * __restrict,
4203eb244d8Sjoerg     __va_list)
4218a601553Sjoerg 		__printflike(2, 0);
422a2cd7322Sperry const char *fmtcheck(const char *, const char *)
4238a601553Sjoerg 		__format_arg(2);
42461f28255Scgd __END_DECLS
42561f28255Scgd 
42661f28255Scgd /*
42761f28255Scgd  * Stdio function-access interface.
42861f28255Scgd  */
42961f28255Scgd __BEGIN_DECLS
43019b7469aSperry FILE	*funopen(const void *,
43161f28255Scgd     int (*)(void *, char *, int),
43261f28255Scgd     int (*)(void *, const char *, int),
4331897181aSchristos     off_t (*)(void *, off_t, int),
43419b7469aSperry     int (*)(void *));
4350ed4e38bSchristos FILE	*funopen2(const void *,
4360ed4e38bSchristos     ssize_t (*)(void *, void *, size_t),
4370ed4e38bSchristos     ssize_t (*)(void *, const void *, size_t),
4380ed4e38bSchristos     off_t (*)(void *, off_t, int),
4390ed4e38bSchristos     int (*)(void *),
4400ed4e38bSchristos     int (*)(void *));
44161f28255Scgd __END_DECLS
44261f28255Scgd #define	fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
44361f28255Scgd #define	fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
4440ed4e38bSchristos #define	fropen2(cookie, fn) funopen2(cookie, fn, 0, 0, 0, 0)
4450ed4e38bSchristos #define	fwopen2(cookie, fn) funopen2(cookie, 0, fn, 0, 0, 0)
4464be7a2dcSbjh21 #endif /* _NETBSD_SOURCE */
44761f28255Scgd 
44861f28255Scgd /*
44961f28255Scgd  * Functions internal to the implementation.
45061f28255Scgd  */
45161f28255Scgd __BEGIN_DECLS
45219b7469aSperry int	__srget(FILE *);
45319b7469aSperry int	__swbuf(int, FILE *);
45461f28255Scgd __END_DECLS
45561f28255Scgd 
45661f28255Scgd /*
45761f28255Scgd  * The __sfoo macros are here so that we can
45861f28255Scgd  * define function versions in the C library.
45961f28255Scgd  */
46061f28255Scgd #define	__sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
46161f28255Scgd #if defined(__GNUC__) && defined(__STDC__)
__sputc(int _c,FILE * _p)462e67ad767Sperry static __inline int __sputc(int _c, FILE *_p) {
46361f28255Scgd 	if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
4648e2b2a8fSchristos 		return *_p->_p++ = (unsigned char)_c;
46561f28255Scgd 	else
4668e2b2a8fSchristos 		return __swbuf(_c, _p);
46761f28255Scgd }
46861f28255Scgd #else
46961f28255Scgd /*
47061f28255Scgd  * This has been tuned to generate reasonable code on the vax using pcc.
47161f28255Scgd  */
47261f28255Scgd #define	__sputc(c, p) \
47361f28255Scgd 	(--(p)->_w < 0 ? \
47461f28255Scgd 		(p)->_w >= (p)->_lbfsize ? \
47561f28255Scgd 			(*(p)->_p = (c)), *(p)->_p != '\n' ? \
47661f28255Scgd 				(int)*(p)->_p++ : \
47761f28255Scgd 				__swbuf('\n', p) : \
47861f28255Scgd 			__swbuf((int)(c), p) : \
47961f28255Scgd 		(*(p)->_p = (c), (int)*(p)->_p++))
48061f28255Scgd #endif
48161f28255Scgd 
48261f28255Scgd #define	__sfeof(p)	(((p)->_flags & __SEOF) != 0)
48361f28255Scgd #define	__sferror(p)	(((p)->_flags & __SERR) != 0)
484ede51e40Schristos #define	__sclearerr(p)	((void)((p)->_flags &= (unsigned short)~(__SERR|__SEOF)))
485749de7f2Schristos #define	__sfileno(p)	\
486749de7f2Schristos     ((p)->_file == -1 ? -1 : (int)(unsigned short)(p)->_file)
48761f28255Scgd 
488cd8f66edSjoerg #if !defined(__lint__) && !defined(__cplusplus)
489898beee0Skleink #if !defined(_REENTRANT) && !defined(_PTHREADS)
49061f28255Scgd #define	feof(p)		__sfeof(p)
49161f28255Scgd #define	ferror(p)	__sferror(p)
49261f28255Scgd #define	clearerr(p)	__sclearerr(p)
49361f28255Scgd 
49461f28255Scgd #define	getc(fp)	__sgetc(fp)
49561f28255Scgd #define putc(x, fp)	__sputc(x, fp)
496898beee0Skleink #endif /* !_REENTRANT && !_PTHREADS */
49761f28255Scgd 
49861f28255Scgd #define	getchar()	getc(stdin)
49961f28255Scgd #define	putchar(x)	putc(x, stdout)
500397b763dSjtc 
501cd8f66edSjoerg #endif /* !__lint__ && !__cplusplus */
502cd8f66edSjoerg 
503cd8f66edSjoerg #if (defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
504cd8f66edSjoerg     defined(_NETBSD_SOURCE)) && !defined(__cplusplus)
505898beee0Skleink #if !defined(_REENTRANT) && !defined(_PTHREADS)
506397b763dSjtc #define	fileno(p)	__sfileno(p)
507898beee0Skleink #endif /* !_REENTRANT && !_PTHREADS */
508cd8f66edSjoerg #endif /* !_ANSI_SOURCE && !__cplusplus*/
509397b763dSjtc 
510748dbd74Schristos #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
511a8b7899cSjoerg __BEGIN_DECLS
5123eb244d8Sjoerg int	 vdprintf(int, const char * __restrict, __va_list)
513748dbd74Schristos 		__printflike(2, 0);
514748dbd74Schristos int	 dprintf(int, const char * __restrict, ...)
515748dbd74Schristos 		__printflike(2, 3);
516a8b7899cSjoerg __END_DECLS
517748dbd74Schristos #endif /* (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE) */
518748dbd74Schristos 
5194be7a2dcSbjh21 #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
520cd8f66edSjoerg     defined(_REENTRANT) || defined(_NETBSD_SOURCE) && !defined(__cplusplus)
521397b763dSjtc #define getc_unlocked(fp)	__sgetc(fp)
522397b763dSjtc #define putc_unlocked(x, fp)	__sputc(x, fp)
523397b763dSjtc 
524397b763dSjtc #define getchar_unlocked()	getc_unlocked(stdin)
525397b763dSjtc #define putchar_unlocked(x)	putc_unlocked(x, stdout)
5264be7a2dcSbjh21 #endif /* _POSIX_C_SOURCE >= 199506 || _XOPEN_SOURCE >= 500 || _REENTRANT... */
527397b763dSjtc 
52893b7363cStnozaki #if (_POSIX_C_SOURCE - 0) >= 200809L || (_XOPEN_SOURCE - 0) >= 700 || \
52993b7363cStnozaki     defined(_NETBSD_SOURCE)
530a8b7899cSjoerg __BEGIN_DECLS
53193b7363cStnozaki FILE *fmemopen(void * __restrict, size_t, const char * __restrict);
532faef3224Schristos FILE *open_memstream(char **, size_t *);
533eead6b98Skleink ssize_t	 getdelim(char ** __restrict, size_t * __restrict, int,
534eead6b98Skleink 	    FILE * __restrict);
535eead6b98Skleink ssize_t	 getline(char ** __restrict, size_t * __restrict, FILE * __restrict);
536a8b7899cSjoerg __END_DECLS
53793b7363cStnozaki #endif
53893b7363cStnozaki 
5392561b634Sjoerg #if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE)
5402561b634Sjoerg #  ifndef __LOCALE_T_DECLARED
5412561b634Sjoerg typedef struct _locale		*locale_t;
5422561b634Sjoerg #  define __LOCALE_T_DECLARED
5432561b634Sjoerg #  endif
5446c5ca8f8Sjoerg __BEGIN_DECLS
5452561b634Sjoerg int	 fprintf_l(FILE * __restrict, locale_t, const char * __restrict, ...)
5462561b634Sjoerg 		__printflike(3, 4);
5472561b634Sjoerg int	 vfprintf_l(FILE * __restrict, locale_t, const char * __restrict,
5482561b634Sjoerg 		__va_list) __printflike(3, 0);
5492561b634Sjoerg int	 printf_l(locale_t, const char * __restrict, ...)
5502561b634Sjoerg 		__printflike(2, 3);
5512561b634Sjoerg int	 vprintf_l(locale_t, const char * __restrict, __va_list)
5522561b634Sjoerg 		__printflike(2, 0);
5532561b634Sjoerg int	 asprintf_l(char ** __restrict, locale_t, const char * __restrict, ...)
5542561b634Sjoerg 		__printflike(3, 4);
5552561b634Sjoerg int	 vasprintf_l(char ** __restrict, locale_t, const char * __restrict,
5562561b634Sjoerg     __va_list)
5572561b634Sjoerg 		__printflike(3, 0);
5582561b634Sjoerg int	 vdprintf_l(int, locale_t, const char * __restrict, __va_list)
5592561b634Sjoerg 		__printflike(3, 0);
5602561b634Sjoerg int	 dprintf_l(int, locale_t, const char * __restrict, ...)
5612561b634Sjoerg 		__printflike(3, 4);
5622561b634Sjoerg int	 snprintf_l(char * __restrict, size_t, locale_t,
5632561b634Sjoerg 		    const char * __restrict, ...) __printflike(4, 5);
5642561b634Sjoerg int	 vsnprintf_l(char * __restrict, size_t, locale_t,
5652561b634Sjoerg 		     const char * __restrict, __va_list) __printflike(4, 0);
5662561b634Sjoerg #ifndef __AUDIT__
5672561b634Sjoerg int	 sprintf_l(char * __restrict, locale_t, const char * __restrict, ...)
5682561b634Sjoerg 		   __printflike(3, 4);
5692561b634Sjoerg int	 vsprintf_l(char * __restrict, locale_t, const char * __restrict,
5702561b634Sjoerg 		    __va_list) __printflike(3, 0);
5712561b634Sjoerg #endif
5729790c07aSjoerg 
5739790c07aSjoerg int	 fscanf_l(FILE * __restrict, locale_t, const char * __restrict, ...)
5749790c07aSjoerg     __scanflike(3, 4);
5759790c07aSjoerg int	 scanf_l(locale_t, const char * __restrict, ...)
5769790c07aSjoerg     __scanflike(2, 3);
5779790c07aSjoerg int	 sscanf_l(const char * __restrict, locale_t,
5789790c07aSjoerg     const char * __restrict, ...) __scanflike(3, 4);
5799790c07aSjoerg int	 vscanf_l(locale_t, const char * __restrict, __va_list)
5809790c07aSjoerg     __scanflike(2, 0);
5819790c07aSjoerg int	 vfscanf_l(FILE * __restrict, locale_t, const char * __restrict,
5829790c07aSjoerg     __va_list) __scanflike(3, 0);
5839790c07aSjoerg int	 vsscanf_l(const char * __restrict, locale_t, const char * __restrict,
5849790c07aSjoerg     __va_list) __scanflike(3, 0);
585df2bc3e4Schristos #ifdef _NETBSD_SOURCE
586df2bc3e4Schristos int	snprintf_ss(char *restrict, size_t, const char * __restrict, ...)
587df2bc3e4Schristos     __printflike(3, 4);
588df2bc3e4Schristos int	vsnprintf_ss(char *restrict, size_t, const char * __restrict, __va_list)
589df2bc3e4Schristos     __printflike(3, 0);
590df2bc3e4Schristos #endif
5916c5ca8f8Sjoerg __END_DECLS
5922561b634Sjoerg #endif
5932561b634Sjoerg 
5941ef79ebcSkristerw #if _FORTIFY_SOURCE > 0
595dc99372bStls #include <ssp/stdio.h>
5961ef79ebcSkristerw #endif
597dc99372bStls 
59861f28255Scgd #endif /* _STDIO_H_ */
599