| 1 | /*	$OpenBSD: stdio.h,v 1.57 2025/07/16 15:33:05 yasuoka Exp $	*/ |
| 2 | /*	$NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $	*/ |
| 3 | |
| 4 | /*- |
| 5 | * Copyright (c) 1990 The Regents of the University of California. |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * This code is derived from software contributed to Berkeley by |
| 9 | * Chris Torek. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * 3. Neither the name of the University nor the names of its contributors |
| 20 | * may be used to endorse or promote products derived from this software |
| 21 | * without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 33 | * SUCH DAMAGE. |
| 34 | * |
| 35 | *	@(#)stdio.h	5.17 (Berkeley) 6/3/91 |
| 36 | */ |
| 37 | |
| 38 | #ifndef	_STDIO_H_ |
| 39 | #define	_STDIO_H_ |
| 40 | |
| 41 | #include <sys/cdefs.h> |
| 42 | #include <sys/_null.h> |
| 43 | #include <sys/_types.h> |
| 44 | |
| 45 | #if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE |
| 46 | #include <sys/types.h>	/* XXX should be removed */ |
| 47 | #endif |
| 48 | |
| 49 | #ifndef	_SIZE_T_DEFINED_ |
| 50 | #define	_SIZE_T_DEFINED_ |
| 51 | typedef	__size_t	size_t; |
| 52 | #endif |
| 53 | |
| 54 | #ifndef	_OFF_T_DEFINED_ |
| 55 | #define	_OFF_T_DEFINED_ |
| 56 | typedef	__off_t	off_t; |
| 57 | #endif |
| 58 | |
| 59 | #define	_FSTDIO			/* Define for new stdio with functions. */ |
| 60 | |
| 61 | typedef off_t fpos_t;		/* stdio file position type */ |
| 62 | |
| 63 | #ifndef	_STDFILES_DECLARED |
| 64 | #define	_STDFILES_DECLARED |
| 65 | typedef	struct __sFILE FILE; |
| 66 | struct __sFstub { long _stub; }; |
| 67 | |
| 68 | __BEGIN_DECLS |
| 69 | extern struct __sFstub __stdin[]; |
| 70 | extern struct __sFstub __stdout[]; |
| 71 | extern struct __sFstub __stderr[]; |
| 72 | __END_DECLS |
| 73 | #endif |
| 74 | |
| 75 | #define	stdin	((struct __sFILE *)__stdin) |
| 76 | #define	stdout	((struct __sFILE *)__stdout) |
| 77 | #define	stderr	((struct __sFILE *)__stderr) |
| 78 | |
| 79 | /* |
| 80 | * The following three definitions are for ANSI C, which took them |
| 81 | * from System V, which brilliantly took internal interface macros and |
| 82 | * made them official arguments to setvbuf(), without renaming them. |
| 83 | * Hence, these ugly _IOxxx names are *supposed* to appear in user code. |
| 84 | * |
| 85 | * Although numbered as their counterparts above, the implementation |
| 86 | * does not rely on this. |
| 87 | */ |
| 88 | #define	_IOFBF	0		/* setvbuf should set fully buffered */ |
| 89 | #define	_IOLBF	1		/* setvbuf should set line buffered */ |
| 90 | #define	_IONBF	2		/* setvbuf should set unbuffered */ |
| 91 | |
| 92 | #define	BUFSIZ	1024		/* size of buffer used by setbuf */ |
| 93 | |
| 94 | #define	EOF	(-1) |
| 95 | |
| 96 | /* |
| 97 | * FOPEN_MAX is a minimum maximum, and should be the number of descriptors |
| 98 | * that the kernel can provide without allocation of a resource that can |
| 99 | * fail without the process sleeping. Do not use this for anything. |
| 100 | */ |
| 101 | #define	FOPEN_MAX	20	/* must be <= OPEN_MAX <sys/syslimits.h> */ |
| 102 | #define	FILENAME_MAX	1024	/* must be <= PATH_MAX <sys/syslimits.h> */ |
| 103 | |
| 104 | /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ |
| 105 | #if __BSD_VISIBLE || __XPG_VISIBLE |
| 106 | #define	P_tmpdir	"/tmp/" |
| 107 | #endif |
| 108 | #define	L_tmpnam	1024	/* XXX must be == PATH_MAX */ |
| 109 | #define	TMP_MAX		0x7fffffff	/* more, but don't overflow int */ |
| 110 | |
| 111 | #ifndef SEEK_SET |
| 112 | #define	SEEK_SET	0	/* set file offset to offset */ |
| 113 | #endif |
| 114 | #ifndef SEEK_CUR |
| 115 | #define	SEEK_CUR	1	/* set file offset to current plus offset */ |
| 116 | #endif |
| 117 | #ifndef SEEK_END |
| 118 | #define	SEEK_END	2	/* set file offset to EOF plus offset */ |
| 119 | #endif |
| 120 | |
| 121 | /* |
| 122 | * Functions defined in ANSI C standard. |
| 123 | */ |
| 124 | __BEGIN_DECLS |
| 125 | void	 clearerr(FILE *); |
| 126 | #if __POSIX_VISIBLE >= 200809 |
| 127 | int	 dprintf(int, const char * __restrict, ...) |
| 128 | 		__attribute__((__format__ (printf, 2, 3))) |
| 129 | 		__attribute__((__nonnull__ (2))); |
| 130 | #endif |
| 131 | int	 fclose(FILE *); |
| 132 | int	 feof(FILE *); |
| 133 | int	 ferror(FILE *); |
| 134 | int	 fflush(FILE *); |
| 135 | int	 fgetc(FILE *); |
| 136 | int	 fgetpos(FILE *, fpos_t *); |
| 137 | char	*fgets(char *, int, FILE *) |
| 138 | 		__attribute__((__bounded__ (__string__,1,2))); |
| 139 | FILE	*fopen(const char *, const char *); |
| 140 | int	 fprintf(FILE *, const char * __restrict, ...); |
| 141 | int	 fputc(int, FILE *); |
| 142 | int	 fputs(const char *, FILE *); |
| 143 | size_t	 fread(void *, size_t, size_t, FILE *) |
| 144 | 		__attribute__((__bounded__ (__size__,1,3,2))); |
| 145 | FILE	*freopen(const char *, const char *, FILE *); |
| 146 | int	 fscanf(FILE *, const char *, ...); |
| 147 | int	 fseek(FILE *, long, int); |
| 148 | int	 fseeko(FILE *, off_t, int); |
| 149 | int	 fsetpos(FILE *, const fpos_t *); |
| 150 | long	 ftell(FILE *); |
| 151 | off_t	 ftello(FILE *); |
| 152 | size_t	 fwrite(const void *, size_t, size_t, FILE *) |
| 153 | 		__attribute__((__bounded__ (__size__,1,3,2))); |
| 154 | int	 getc(FILE *); |
| 155 | int	 getchar(void); |
| 156 | #if __POSIX_VISIBLE >= 200809 |
| 157 | ssize_t	 getdelim(char ** __restrict, size_t * __restrict, int, |
| 158 | 	 FILE * __restrict); |
| 159 | ssize_t	 getline(char ** __restrict, size_t * __restrict, |
| 160 | 	 FILE * __restrict); |
| 161 | #endif |
| 162 | #if __BSD_VISIBLE && !defined(__SYS_ERRLIST) |
| 163 | #define __SYS_ERRLIST |
| 164 | |
| 165 | extern int sys_nerr;			/* perror(3) external variables */ |
| 166 | extern char *sys_errlist[]; |
| 167 | #endif |
| 168 | void	 perror(const char *); |
| 169 | int	 printf(const char * __restrict, ...); |
| 170 | int	 putc(int, FILE *); |
| 171 | int	 putchar(int); |
| 172 | int	 puts(const char *); |
| 173 | int	 remove(const char *); |
| 174 | int	 rename(const char *, const char *); |
| 175 | #if __POSIX_VISIBLE >= 200809 |
| 176 | int	 renameat(int, const char *, int, const char *); |
| 177 | #endif |
| 178 | void	 rewind(FILE *); |
| 179 | int	 scanf(const char *, ...); |
| 180 | void	 setbuf(FILE *, char *); |
| 181 | int	 setvbuf(FILE *, char *, int, size_t); |
| 182 | int	 sprintf(char * __restrict, const char * __restrict, ...); |
| 183 | int	 sscanf(const char *, const char *, ...); |
| 184 | FILE	*tmpfile(void); |
| 185 | char	*tmpnam(char *); |
| 186 | int	 ungetc(int, FILE *); |
| 187 | int	 vfprintf(FILE *, const char * __restrict, __va_list); |
| 188 | int	 vprintf(const char * __restrict, __va_list); |
| 189 | int	 vsprintf(char * __restrict, const char * __restrict, __va_list); |
| 190 | #if __POSIX_VISIBLE >= 200809 |
| 191 | int	 vdprintf(int, const char * __restrict, __va_list) |
| 192 | 		__attribute__((__format__ (printf, 2, 0))) |
| 193 | 		__attribute__((__nonnull__ (2))); |
| 194 | #endif |
| 195 | |
| 196 | #if __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE >= 500 || __BSD_VISIBLE |
| 197 | int	 snprintf(char * __restrict, size_t, const char * __restrict, ...) |
| 198 | 		__attribute__((__format__ (printf, 3, 4))) |
| 199 | 		__attribute__((__nonnull__ (3))) |
| 200 | 		__attribute__((__bounded__ (__string__,1,2))); |
| 201 | int	 vsnprintf(char * __restrict, size_t, const char * __restrict, |
| 202 | 	 __va_list) |
| 203 | 		__attribute__((__format__ (printf, 3, 0))) |
| 204 | 		__attribute__((__nonnull__ (3))) |
| 205 | 		__attribute__((__bounded__(__string__,1,2))); |
| 206 | #endif /* __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE >= 500 || __BSD_VISIBLE */ |
| 207 | |
| 208 | #if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE |
| 209 | int	 vfscanf(FILE *, const char *, __va_list) |
| 210 | 		__attribute__((__format__ (scanf, 2, 0))) |
| 211 | 		__attribute__((__nonnull__ (2))); |
| 212 | int	 vscanf(const char *, __va_list) |
| 213 | 		__attribute__((__format__ (scanf, 1, 0))) |
| 214 | 		__attribute__((__nonnull__ (1))); |
| 215 | int	 vsscanf(const char *, const char *, __va_list) |
| 216 | 		__attribute__((__format__ (scanf, 2, 0))) |
| 217 | 		__attribute__((__nonnull__ (2))); |
| 218 | #endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */ |
| 219 | |
| 220 | __END_DECLS |
| 221 | |
| 222 | |
| 223 | /* |
| 224 | * Functions defined in POSIX 1003.1. |
| 225 | */ |
| 226 | #if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE |
| 227 | #define	L_ctermid	1024	/* size for ctermid(); PATH_MAX */ |
| 228 | |
| 229 | __BEGIN_DECLS |
| 230 | char	*ctermid(char *); |
| 231 | FILE	*fdopen(int, const char *); |
| 232 | int	 fileno(FILE *); |
| 233 | |
| 234 | #if __POSIX_VISIBLE >= 199209 |
| 235 | int	 pclose(FILE *); |
| 236 | FILE	*popen(const char *, const char *); |
| 237 | #endif |
| 238 | |
| 239 | #if __POSIX_VISIBLE >= 199506 |
| 240 | void	 flockfile(FILE *); |
| 241 | int	 ftrylockfile(FILE *); |
| 242 | void	 funlockfile(FILE *); |
| 243 | |
| 244 | /* |
| 245 | * These are normally used through macros as defined below, but POSIX |
| 246 | * requires functions as well. |
| 247 | */ |
| 248 | int	 getc_unlocked(FILE *); |
| 249 | int	 getchar_unlocked(void); |
| 250 | int	 putc_unlocked(int, FILE *); |
| 251 | int	 putchar_unlocked(int); |
| 252 | #endif /* __POSIX_VISIBLE >= 199506 */ |
| 253 | |
| 254 | #if __POSIX_VISIBLE >= 200809 |
| 255 | FILE	*fmemopen(void *, size_t, const char *); |
| 256 | FILE	*open_memstream(char **, size_t *); |
| 257 | #endif /* __POSIX_VISIBLE >= 200809 */ |
| 258 | |
| 259 | #if __XPG_VISIBLE |
| 260 | char	*tempnam(const char *, const char *); |
| 261 | #endif |
| 262 | |
| 263 | #if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE |
| 264 | int	 asprintf(char ** __restrict, const char * __restrict, ...) |
| 265 | 		__attribute__((__format__ (printf, 2, 3))) |
| 266 | 		__attribute__((__nonnull__ (2))); |
| 267 | int	 vasprintf(char ** __restrict, const char * __restrict, __va_list) |
| 268 | 		__attribute__((__format__ (printf, 2, 0))) |
| 269 | 		__attribute__((__nonnull__ (2))); |
| 270 | #endif /* __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE */ |
| 271 | __END_DECLS |
| 272 | |
| 273 | #endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */ |
| 274 | |
| 275 | /* |
| 276 | * Routines that are purely local. |
| 277 | */ |
| 278 | #if __BSD_VISIBLE |
| 279 | __BEGIN_DECLS |
| 280 | int	 fdclose(FILE *, int *_fdp); |
| 281 | char	*fgetln(FILE *, size_t *); |
| 282 | int	 fpurge(FILE *); |
| 283 | int	 getw(FILE *); |
| 284 | int	 putw(int, FILE *); |
| 285 | void	 setbuffer(FILE *, char *, int); |
| 286 | int	 setlinebuf(FILE *); |
| 287 | __END_DECLS |
| 288 | |
| 289 | /* |
| 290 | * Stdio function-access interface. |
| 291 | */ |
| 292 | __BEGIN_DECLS |
| 293 | FILE	*funopen(const void *, |
| 294 | 		int (*)(void *, char *, int), |
| 295 | 		int (*)(void *, const char *, int), |
| 296 | 		off_t (*)(void *, off_t, int), |
| 297 | 		int (*)(void *)); |
| 298 | __END_DECLS |
| 299 | #define	fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) |
| 300 | #define	fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) |
| 301 | #endif /* __BSD_VISIBLE */ |
| 302 | |
| 303 | #define	getchar()	getc(stdin) |
| 304 | #define	putchar(x)	putc(x, stdout) |
| 305 | #define getchar_unlocked()	getc_unlocked(stdin) |
| 306 | #define putchar_unlocked(c)	putc_unlocked(c, stdout) |
| 307 | |
| 308 | #endif /* _STDIO_H_ */ |