Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | #ifndef _STDIO_H |
| 2 | #define _STDIO_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
Rich Felker | c1a9658 | 2012-09-07 23:13:55 -0400 | [diff] [blame] | 8 | #include <features.h> |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 9 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 10 | #define __NEED_FILE |
Rich Felker | a3e2f3c | 2013-06-25 22:26:20 -0400 | [diff] [blame] | 11 | #define __NEED___isoc_va_list |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 12 | #define __NEED_size_t |
Rich Felker | 80695b1 | 2011-02-14 05:10:10 -0500 | [diff] [blame] | 13 | |
Rich Felker | f368d9f | 2019-03-12 15:24:00 -0400 | [diff] [blame] | 14 | #if __STDC_VERSION__ < 201112L |
| 15 | #define __NEED_struct__IO_FILE |
| 16 | #endif |
| 17 | |
Rich Felker | 80695b1 | 2011-02-14 05:10:10 -0500 | [diff] [blame] | 18 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ |
Rich Felker | 419ae6d | 2012-05-22 21:52:08 -0400 | [diff] [blame] | 19 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ |
| 20 | || defined(_BSD_SOURCE) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 21 | #define __NEED_ssize_t |
| 22 | #define __NEED_off_t |
Rich Felker | a3e2f3c | 2013-06-25 22:26:20 -0400 | [diff] [blame] | 23 | #define __NEED_va_list |
Rich Felker | 80695b1 | 2011-02-14 05:10:10 -0500 | [diff] [blame] | 24 | #endif |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 25 | |
| 26 | #include <bits/alltypes.h> |
| 27 | |
Ismael Luceno | 98e688a | 2021-08-15 17:51:57 +0200 | [diff] [blame] | 28 | #if __cplusplus >= 201103L |
| 29 | #define NULL nullptr |
| 30 | #elif defined(__cplusplus) |
Rich Felker | 41d7c77 | 2013-01-18 20:35:26 -0500 | [diff] [blame] | 31 | #define NULL 0L |
Rich Felker | c8a9c22 | 2013-11-24 21:42:55 -0500 | [diff] [blame] | 32 | #else |
| 33 | #define NULL ((void*)0) |
| 34 | #endif |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 35 | |
| 36 | #undef EOF |
| 37 | #define EOF (-1) |
| 38 | |
| 39 | #undef SEEK_SET |
| 40 | #undef SEEK_CUR |
| 41 | #undef SEEK_END |
| 42 | #define SEEK_SET 0 |
| 43 | #define SEEK_CUR 1 |
| 44 | #define SEEK_END 2 |
| 45 | |
| 46 | #define _IOFBF 0 |
| 47 | #define _IOLBF 1 |
| 48 | #define _IONBF 2 |
| 49 | |
Rich Felker | 571312d | 2011-02-15 19:47:22 -0500 | [diff] [blame] | 50 | #define BUFSIZ 1024 |
Rich Felker | b823ef2 | 2013-07-18 14:15:48 -0400 | [diff] [blame] | 51 | #define FILENAME_MAX 4096 |
Rich Felker | 571312d | 2011-02-15 19:47:22 -0500 | [diff] [blame] | 52 | #define FOPEN_MAX 1000 |
| 53 | #define TMP_MAX 10000 |
| 54 | #define L_tmpnam 20 |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 55 | |
Rich Felker | 9448b05 | 2013-07-22 11:22:36 -0400 | [diff] [blame] | 56 | typedef union _G_fpos64_t { |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 57 | char __opaque[16]; |
Rich Felker | 2fae10f | 2018-02-24 16:45:33 -0500 | [diff] [blame] | 58 | long long __lldata; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 59 | double __align; |
| 60 | } fpos_t; |
| 61 | |
| 62 | extern FILE *const stdin; |
| 63 | extern FILE *const stdout; |
| 64 | extern FILE *const stderr; |
| 65 | |
| 66 | #define stdin (stdin) |
| 67 | #define stdout (stdout) |
| 68 | #define stderr (stderr) |
| 69 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 70 | FILE *fopen(const char *__restrict, const char *__restrict); |
| 71 | FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 72 | int fclose(FILE *); |
| 73 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 74 | int remove(const char *); |
| 75 | int rename(const char *, const char *); |
| 76 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 77 | int feof(FILE *); |
| 78 | int ferror(FILE *); |
| 79 | int fflush(FILE *); |
| 80 | void clearerr(FILE *); |
| 81 | |
| 82 | int fseek(FILE *, long, int); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 83 | long ftell(FILE *); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 84 | void rewind(FILE *); |
| 85 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 86 | int fgetpos(FILE *__restrict, fpos_t *__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 87 | int fsetpos(FILE *, const fpos_t *); |
| 88 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 89 | size_t fread(void *__restrict, size_t, size_t, FILE *__restrict); |
| 90 | size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 91 | |
| 92 | int fgetc(FILE *); |
| 93 | int getc(FILE *); |
| 94 | int getchar(void); |
| 95 | int ungetc(int, FILE *); |
| 96 | |
| 97 | int fputc(int, FILE *); |
| 98 | int putc(int, FILE *); |
| 99 | int putchar(int); |
| 100 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 101 | char *fgets(char *__restrict, int, FILE *__restrict); |
Rich Felker | 9bff7c1 | 2012-08-25 23:15:13 -0400 | [diff] [blame] | 102 | #if __STDC_VERSION__ < 201112L |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 103 | char *gets(char *); |
Rich Felker | 9bff7c1 | 2012-08-25 23:15:13 -0400 | [diff] [blame] | 104 | #endif |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 105 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 106 | int fputs(const char *__restrict, FILE *__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 107 | int puts(const char *); |
| 108 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 109 | int printf(const char *__restrict, ...); |
| 110 | int fprintf(FILE *__restrict, const char *__restrict, ...); |
| 111 | int sprintf(char *__restrict, const char *__restrict, ...); |
| 112 | int snprintf(char *__restrict, size_t, const char *__restrict, ...); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 113 | |
Rich Felker | a3e2f3c | 2013-06-25 22:26:20 -0400 | [diff] [blame] | 114 | int vprintf(const char *__restrict, __isoc_va_list); |
| 115 | int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list); |
| 116 | int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list); |
| 117 | int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 118 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 119 | int scanf(const char *__restrict, ...); |
| 120 | int fscanf(FILE *__restrict, const char *__restrict, ...); |
| 121 | int sscanf(const char *__restrict, const char *__restrict, ...); |
Rich Felker | a3e2f3c | 2013-06-25 22:26:20 -0400 | [diff] [blame] | 122 | int vscanf(const char *__restrict, __isoc_va_list); |
| 123 | int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list); |
| 124 | int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 125 | |
| 126 | void perror(const char *); |
| 127 | |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 128 | int setvbuf(FILE *__restrict, char *__restrict, int, size_t); |
| 129 | void setbuf(FILE *__restrict, char *__restrict); |
Rich Felker | 80695b1 | 2011-02-14 05:10:10 -0500 | [diff] [blame] | 130 | |
| 131 | char *tmpnam(char *); |
| 132 | FILE *tmpfile(void); |
| 133 | |
| 134 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ |
Rich Felker | 419ae6d | 2012-05-22 21:52:08 -0400 | [diff] [blame] | 135 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ |
| 136 | || defined(_BSD_SOURCE) |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 137 | FILE *fmemopen(void *__restrict, size_t, const char *__restrict); |
Rich Felker | b158b32 | 2011-09-03 00:45:21 -0400 | [diff] [blame] | 138 | FILE *open_memstream(char **, size_t *); |
Rich Felker | 80695b1 | 2011-02-14 05:10:10 -0500 | [diff] [blame] | 139 | FILE *fdopen(int, const char *); |
| 140 | FILE *popen(const char *, const char *); |
| 141 | int pclose(FILE *); |
| 142 | int fileno(FILE *); |
| 143 | int fseeko(FILE *, off_t, int); |
| 144 | off_t ftello(FILE *); |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 145 | int dprintf(int, const char *__restrict, ...); |
Rich Felker | a3e2f3c | 2013-06-25 22:26:20 -0400 | [diff] [blame] | 146 | int vdprintf(int, const char *__restrict, __isoc_va_list); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 147 | void flockfile(FILE *); |
| 148 | int ftrylockfile(FILE *); |
| 149 | void funlockfile(FILE *); |
| 150 | int getc_unlocked(FILE *); |
| 151 | int getchar_unlocked(void); |
| 152 | int putc_unlocked(int, FILE *); |
| 153 | int putchar_unlocked(int); |
Rich Felker | 400c5e5 | 2012-09-06 22:44:55 -0400 | [diff] [blame] | 154 | ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); |
| 155 | ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 156 | int renameat(int, const char *, int, const char *); |
Rich Felker | 80695b1 | 2011-02-14 05:10:10 -0500 | [diff] [blame] | 157 | char *ctermid(char *); |
Rich Felker | 571312d | 2011-02-15 19:47:22 -0500 | [diff] [blame] | 158 | #define L_ctermid 20 |
Rich Felker | 80695b1 | 2011-02-14 05:10:10 -0500 | [diff] [blame] | 159 | #endif |
| 160 | |
| 161 | |
Rich Felker | 419ae6d | 2012-05-22 21:52:08 -0400 | [diff] [blame] | 162 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ |
| 163 | || defined(_BSD_SOURCE) |
Rich Felker | 571312d | 2011-02-15 19:47:22 -0500 | [diff] [blame] | 164 | #define P_tmpdir "/tmp" |
Rich Felker | 80695b1 | 2011-02-14 05:10:10 -0500 | [diff] [blame] | 165 | char *tempnam(const char *, const char *); |
| 166 | #endif |
| 167 | |
Rich Felker | 419ae6d | 2012-05-22 21:52:08 -0400 | [diff] [blame] | 168 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
Rich Felker | 571312d | 2011-02-15 19:47:22 -0500 | [diff] [blame] | 169 | #define L_cuserid 20 |
| 170 | char *cuserid(char *); |
Rich Felker | e721800 | 2011-04-05 12:25:31 -0400 | [diff] [blame] | 171 | void setlinebuf(FILE *); |
| 172 | void setbuffer(FILE *, char *, size_t); |
Rich Felker | ce17ea6 | 2011-09-11 22:50:02 -0400 | [diff] [blame] | 173 | int fgetc_unlocked(FILE *); |
| 174 | int fputc_unlocked(int, FILE *); |
Rich Felker | b63cab7 | 2012-05-28 22:53:24 -0400 | [diff] [blame] | 175 | int fflush_unlocked(FILE *); |
| 176 | size_t fread_unlocked(void *, size_t, size_t, FILE *); |
| 177 | size_t fwrite_unlocked(const void *, size_t, size_t, FILE *); |
| 178 | void clearerr_unlocked(FILE *); |
| 179 | int feof_unlocked(FILE *); |
| 180 | int ferror_unlocked(FILE *); |
| 181 | int fileno_unlocked(FILE *); |
Rich Felker | 25b88f0 | 2012-07-04 12:18:04 -0400 | [diff] [blame] | 182 | int getw(FILE *); |
| 183 | int putw(int, FILE *); |
Rich Felker | 6171827 | 2012-08-11 18:10:38 -0400 | [diff] [blame] | 184 | char *fgetln(FILE *, size_t *); |
Rich Felker | d18a410 | 2012-12-28 15:39:33 -0500 | [diff] [blame] | 185 | int asprintf(char **, const char *, ...); |
Rich Felker | a3e2f3c | 2013-06-25 22:26:20 -0400 | [diff] [blame] | 186 | int vasprintf(char **, const char *, __isoc_va_list); |
Rich Felker | 6171827 | 2012-08-11 18:10:38 -0400 | [diff] [blame] | 187 | #endif |
| 188 | |
Rich Felker | b63cab7 | 2012-05-28 22:53:24 -0400 | [diff] [blame] | 189 | #ifdef _GNU_SOURCE |
Rich Felker | ce17ea6 | 2011-09-11 22:50:02 -0400 | [diff] [blame] | 190 | char *fgets_unlocked(char *, int, FILE *); |
| 191 | int fputs_unlocked(const char *, FILE *); |
William Pitcock | 0618433 | 2017-12-05 16:04:43 -0500 | [diff] [blame] | 192 | |
| 193 | typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); |
| 194 | typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); |
| 195 | typedef int (cookie_seek_function_t)(void *, off_t *, int); |
| 196 | typedef int (cookie_close_function_t)(void *); |
| 197 | |
Rich Felker | 2488d31 | 2017-12-06 13:14:22 -0500 | [diff] [blame] | 198 | typedef struct _IO_cookie_io_functions_t { |
William Pitcock | 0618433 | 2017-12-05 16:04:43 -0500 | [diff] [blame] | 199 | cookie_read_function_t *read; |
| 200 | cookie_write_function_t *write; |
| 201 | cookie_seek_function_t *seek; |
| 202 | cookie_close_function_t *close; |
| 203 | } cookie_io_functions_t; |
| 204 | |
| 205 | FILE *fopencookie(void *, const char *, cookie_io_functions_t); |
Rich Felker | 80695b1 | 2011-02-14 05:10:10 -0500 | [diff] [blame] | 206 | #endif |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 207 | |
Rich Felker | 3b94dab | 2012-06-04 08:03:56 -0400 | [diff] [blame] | 208 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) |
Rich Felker | 2dd8d5e | 2012-05-04 00:13:23 -0400 | [diff] [blame] | 209 | #define tmpfile64 tmpfile |
| 210 | #define fopen64 fopen |
| 211 | #define freopen64 freopen |
| 212 | #define fseeko64 fseeko |
| 213 | #define ftello64 ftello |
| 214 | #define fgetpos64 fgetpos |
| 215 | #define fsetpos64 fsetpos |
| 216 | #define fpos64_t fpos_t |
| 217 | #define off64_t off_t |
| 218 | #endif |
| 219 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 220 | #ifdef __cplusplus |
| 221 | } |
| 222 | #endif |
| 223 | |
| 224 | #endif |