1 #ifndef _STDIO_H 2 #define _STDIO_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #include <features.h> 9 #include <stdint.h> 10 11 #define __NEED_FILE 12 #define __NEED___isoc_va_list 13 #define __NEED_size_t 14 15 #if __STDC_VERSION__ < 201112L 16 #define __NEED_struct__IO_FILE 17 #endif 18 19 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 20 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 21 || defined(_BSD_SOURCE) 22 #define __NEED_ssize_t 23 #define __NEED_off_t 24 #define __NEED_va_list 25 #endif 26 27 #include <bits/alltypes.h> 28 29 #if __cplusplus >= 201103L 30 #define NULL nullptr 31 #elif defined(__cplusplus) 32 #define NULL 0L 33 #else 34 #define NULL ((void*)0) 35 #endif 36 37 #undef EOF 38 #define EOF (-1) 39 40 #undef SEEK_SET 41 #undef SEEK_CUR 42 #undef SEEK_END 43 #define SEEK_SET 0 44 #define SEEK_CUR 1 45 #define SEEK_END 2 46 47 #define _IOFBF 0 48 #define _IOLBF 1 49 #define _IONBF 2 50 51 #define BUFSIZ 1024 52 #define FILENAME_MAX 4096 53 #define FOPEN_MAX 1000 54 #define TMP_MAX 10000 55 #define L_tmpnam 20 56 57 typedef union _G_fpos64_t { 58 char __opaque[16]; 59 long long __lldata; 60 double __align; 61 } fpos_t; 62 63 extern FILE *const stdin; 64 extern FILE *const stdout; 65 extern FILE *const stderr; 66 67 #define stdin (stdin) 68 #define stdout (stdout) 69 #define stderr (stderr) 70 71 FILE *fopen(const char *__restrict, const char *__restrict); 72 FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict); 73 int fclose(FILE *); 74 75 int remove(const char *); 76 int rename(const char *, const char *); 77 78 int feof(FILE *); 79 int ferror(FILE *); 80 int fflush(FILE *); 81 void clearerr(FILE *); 82 83 int fseek(FILE *, long, int); 84 long ftell(FILE *); 85 void rewind(FILE *); 86 87 int fgetpos(FILE *__restrict, fpos_t *__restrict); 88 int fsetpos(FILE *, const fpos_t *); 89 90 size_t fread(void *__restrict, size_t, size_t, FILE *__restrict); 91 size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict); 92 93 int fgetc(FILE *); 94 int getc(FILE *); 95 int getchar(void); 96 int ungetc(int, FILE *); 97 98 int fputc(int, FILE *); 99 int putc(int, FILE *); 100 int putchar(int); 101 102 char *fgets(char *__restrict, int, FILE *__restrict); 103 #if __STDC_VERSION__ < 201112L 104 char *gets(char *); 105 #endif 106 107 int fputs(const char *__restrict, FILE *__restrict); 108 int puts(const char *); 109 110 int printf(const char *__restrict, ...); 111 int fprintf(FILE *__restrict, const char *__restrict, ...); 112 int sprintf(char *__restrict, const char *__restrict, ...); 113 int snprintf(char *__restrict, size_t, const char *__restrict, ...); 114 115 int vprintf(const char *__restrict, __isoc_va_list); 116 int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list); 117 int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list); 118 int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list); 119 120 int scanf(const char *__restrict, ...); 121 int fscanf(FILE *__restrict, const char *__restrict, ...); 122 int sscanf(const char *__restrict, const char *__restrict, ...); 123 int vscanf(const char *__restrict, __isoc_va_list); 124 int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list); 125 int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list); 126 127 void perror(const char *); 128 129 int setvbuf(FILE *__restrict, char *__restrict, int, size_t); 130 void setbuf(FILE *__restrict, char *__restrict); 131 132 char *tmpnam(char *); 133 FILE *tmpfile(void); 134 135 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ 136 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 137 || defined(_BSD_SOURCE) 138 FILE *fmemopen(void *__restrict, size_t, const char *__restrict); 139 FILE *open_memstream(char **, size_t *); 140 FILE *fdopen(int, const char *); 141 FILE *popen(const char *, const char *); 142 int pclose(FILE *); 143 int fileno(FILE *); 144 int fseeko(FILE *, off_t, int); 145 off_t ftello(FILE *); 146 int dprintf(int, const char *__restrict, ...); 147 int vdprintf(int, const char *__restrict, __isoc_va_list); 148 void flockfile(FILE *); 149 int ftrylockfile(FILE *); 150 void funlockfile(FILE *); 151 int getc_unlocked(FILE *); 152 int getchar_unlocked(void); 153 int putc_unlocked(int, FILE *); 154 int putchar_unlocked(int); 155 ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); 156 ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict); 157 int renameat(int, const char *, int, const char *); 158 #define RENAME_NOREPLACE (1 << 0) 159 #define RENAME_EXCHANGE (1 << 1) 160 #define RENAME_WHITEOUT (1 << 2) 161 int renameat2(int, const char *, int, const char *, unsigned int); 162 char *ctermid(char *); 163 #define L_ctermid 20 164 #endif 165 166 167 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ 168 || defined(_BSD_SOURCE) 169 #define P_tmpdir "/tmp" 170 char *tempnam(const char *, const char *); 171 #endif 172 173 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) 174 #define L_cuserid 20 175 char *cuserid(char *); 176 void setlinebuf(FILE *); 177 void setbuffer(FILE *, char *, size_t); 178 int fgetc_unlocked(FILE *); 179 int fputc_unlocked(int, FILE *); 180 int fflush_unlocked(FILE *); 181 size_t fread_unlocked(void *, size_t, size_t, FILE *); 182 size_t fwrite_unlocked(const void *, size_t, size_t, FILE *); 183 void clearerr_unlocked(FILE *); 184 int feof_unlocked(FILE *); 185 int ferror_unlocked(FILE *); 186 int fileno_unlocked(FILE *); 187 int getw(FILE *); 188 int putw(int, FILE *); 189 char *fgetln(FILE *, size_t *); 190 int asprintf(char **, const char *, ...); 191 int vasprintf(char **, const char *, __isoc_va_list); 192 #endif 193 194 #ifdef _GNU_SOURCE 195 char *fgets_unlocked(char *, int, FILE *); 196 int fputs_unlocked(const char *, FILE *); 197 198 typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); 199 typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); 200 typedef int (cookie_seek_function_t)(void *, off_t *, int); 201 typedef int (cookie_close_function_t)(void *); 202 203 typedef struct _IO_cookie_io_functions_t { 204 cookie_read_function_t *read; 205 cookie_write_function_t *write; 206 cookie_seek_function_t *seek; 207 cookie_close_function_t *close; 208 } cookie_io_functions_t; 209 210 FILE *fopencookie(void *, const char *, cookie_io_functions_t); 211 #endif 212 213 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) 214 #define tmpfile64 tmpfile 215 #define fopen64 fopen 216 #define freopen64 freopen 217 #define fseeko64 fseeko 218 #define ftello64 ftello 219 #define fgetpos64 fgetpos 220 #define fsetpos64 fsetpos 221 #define fpos64_t fpos_t 222 #define off64_t off_t 223 #endif 224 225 enum fdsan_owner_type { 226 FDSAN_OWNER_TYPE_DEFAULT = 0, 227 FDSAN_OWNER_TYPE_MAX = 255, 228 229 /* FILE* */ 230 FDSAN_OWNER_TYPE_FILE = 1, 231 232 /* DIR* */ 233 FDSAN_OWNER_TYPE_DIRECTORY = 2, 234 235 /* unique_fd */ 236 FDSAN_OWNER_TYPE_UNIQUE_FD = 3, 237 238 /* ziparchive */ 239 FDSAN_OWNER_TYPE_ZIP_ARCHIVE = 4, 240 }; 241 242 void* fdsan_get_fd_table(); 243 uint64_t fdsan_create_owner_tag(enum fdsan_owner_type type, uint64_t tag); 244 void fdsan_exchange_owner_tag(int fd, uint64_t expected_tag, uint64_t new_tag); 245 int fdsan_close_with_tag(int fd, uint64_t tag); 246 uint64_t fdsan_get_owner_tag(int fd); 247 const char* fdsan_get_tag_type(uint64_t tag); 248 uint64_t fdsan_get_tag_value(uint64_t tag); 249 250 enum fdsan_error_level { 251 // No errors. 252 FDSAN_ERROR_LEVEL_DISABLED, 253 254 // Warn once(ish) on error, and then downgrade to FDSAN_ERROR_LEVEL_DISABLED. 255 FDSAN_ERROR_LEVEL_WARN_ONCE, 256 257 // Warn always on error. 258 FDSAN_ERROR_LEVEL_WARN_ALWAYS, 259 260 // Abort on error. 261 FDSAN_ERROR_LEVEL_FATAL, 262 }; 263 264 enum fdsan_error_level fdsan_get_error_level(); 265 enum fdsan_error_level fdsan_set_error_level(enum fdsan_error_level new_level); 266 enum fdsan_error_level fdsan_set_error_level_from_param(enum fdsan_error_level default_level); 267 268 #ifndef __LITEOS__ 269 #include <fortify/stdio.h> 270 #endif 271 272 #include <stdarg.h> 273 #ifdef __cplusplus 274 } 275 #endif 276 277 #endif 278