jcs's openbsd hax
openbsd
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_
51typedef __size_t size_t;
52#endif
53
54#ifndef _OFF_T_DEFINED_
55#define _OFF_T_DEFINED_
56typedef __off_t off_t;
57#endif
58
59#define _FSTDIO /* Define for new stdio with functions. */
60
61typedef off_t fpos_t; /* stdio file position type */
62
63#ifndef _STDFILES_DECLARED
64#define _STDFILES_DECLARED
65typedef struct __sFILE FILE;
66struct __sFstub { long _stub; };
67
68__BEGIN_DECLS
69extern struct __sFstub __stdin[];
70extern struct __sFstub __stdout[];
71extern 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
125void clearerr(FILE *);
126#if __POSIX_VISIBLE >= 200809
127int dprintf(int, const char * __restrict, ...)
128 __attribute__((__format__ (printf, 2, 3)))
129 __attribute__((__nonnull__ (2)));
130#endif
131int fclose(FILE *);
132int feof(FILE *);
133int ferror(FILE *);
134int fflush(FILE *);
135int fgetc(FILE *);
136int fgetpos(FILE *, fpos_t *);
137char *fgets(char *, int, FILE *)
138 __attribute__((__bounded__ (__string__,1,2)));
139FILE *fopen(const char *, const char *);
140int fprintf(FILE *, const char * __restrict, ...);
141int fputc(int, FILE *);
142int fputs(const char *, FILE *);
143size_t fread(void *, size_t, size_t, FILE *)
144 __attribute__((__bounded__ (__size__,1,3,2)));
145FILE *freopen(const char *, const char *, FILE *);
146int fscanf(FILE *, const char *, ...);
147int fseek(FILE *, long, int);
148int fseeko(FILE *, off_t, int);
149int fsetpos(FILE *, const fpos_t *);
150long ftell(FILE *);
151off_t ftello(FILE *);
152size_t fwrite(const void *, size_t, size_t, FILE *)
153 __attribute__((__bounded__ (__size__,1,3,2)));
154int getc(FILE *);
155int getchar(void);
156#if __POSIX_VISIBLE >= 200809
157ssize_t getdelim(char ** __restrict, size_t * __restrict, int,
158 FILE * __restrict);
159ssize_t getline(char ** __restrict, size_t * __restrict,
160 FILE * __restrict);
161#endif
162#if __BSD_VISIBLE && !defined(__SYS_ERRLIST)
163#define __SYS_ERRLIST
164
165extern int sys_nerr; /* perror(3) external variables */
166extern char *sys_errlist[];
167#endif
168void perror(const char *);
169int printf(const char * __restrict, ...);
170int putc(int, FILE *);
171int putchar(int);
172int puts(const char *);
173int remove(const char *);
174int rename(const char *, const char *);
175#if __POSIX_VISIBLE >= 200809
176int renameat(int, const char *, int, const char *);
177#endif
178void rewind(FILE *);
179int scanf(const char *, ...);
180void setbuf(FILE *, char *);
181int setvbuf(FILE *, char *, int, size_t);
182int sprintf(char * __restrict, const char * __restrict, ...);
183int sscanf(const char *, const char *, ...);
184FILE *tmpfile(void);
185char *tmpnam(char *);
186int ungetc(int, FILE *);
187int vfprintf(FILE *, const char * __restrict, __va_list);
188int vprintf(const char * __restrict, __va_list);
189int vsprintf(char * __restrict, const char * __restrict, __va_list);
190#if __POSIX_VISIBLE >= 200809
191int 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
197int snprintf(char * __restrict, size_t, const char * __restrict, ...)
198 __attribute__((__format__ (printf, 3, 4)))
199 __attribute__((__nonnull__ (3)))
200 __attribute__((__bounded__ (__string__,1,2)));
201int 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
209int vfscanf(FILE *, const char *, __va_list)
210 __attribute__((__format__ (scanf, 2, 0)))
211 __attribute__((__nonnull__ (2)));
212int vscanf(const char *, __va_list)
213 __attribute__((__format__ (scanf, 1, 0)))
214 __attribute__((__nonnull__ (1)));
215int 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
230char *ctermid(char *);
231FILE *fdopen(int, const char *);
232int fileno(FILE *);
233
234#if __POSIX_VISIBLE >= 199209
235int pclose(FILE *);
236FILE *popen(const char *, const char *);
237#endif
238
239#if __POSIX_VISIBLE >= 199506
240void flockfile(FILE *);
241int ftrylockfile(FILE *);
242void funlockfile(FILE *);
243
244/*
245 * These are normally used through macros as defined below, but POSIX
246 * requires functions as well.
247 */
248int getc_unlocked(FILE *);
249int getchar_unlocked(void);
250int putc_unlocked(int, FILE *);
251int putchar_unlocked(int);
252#endif /* __POSIX_VISIBLE >= 199506 */
253
254#if __POSIX_VISIBLE >= 200809
255FILE *fmemopen(void *, size_t, const char *);
256FILE *open_memstream(char **, size_t *);
257#endif /* __POSIX_VISIBLE >= 200809 */
258
259#if __XPG_VISIBLE
260char *tempnam(const char *, const char *);
261#endif
262
263#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE
264int asprintf(char ** __restrict, const char * __restrict, ...)
265 __attribute__((__format__ (printf, 2, 3)))
266 __attribute__((__nonnull__ (2)));
267int 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
280int fdclose(FILE *, int *_fdp);
281char *fgetln(FILE *, size_t *);
282int fpurge(FILE *);
283int getw(FILE *);
284int putw(int, FILE *);
285void setbuffer(FILE *, char *, int);
286int setlinebuf(FILE *);
287__END_DECLS
288
289/*
290 * Stdio function-access interface.
291 */
292__BEGIN_DECLS
293FILE *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_ */