The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* $OpenBSD: stdio.h,v 1.35 2006/01/13 18:10:09 miod 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> |
Elliott Hughes | 3975cec | 2012-11-29 17:25:23 -0800 | [diff] [blame] | 42 | #include <sys/types.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 43 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 44 | #include <stdarg.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 45 | #include <stddef.h> |
| 46 | |
Elliott Hughes | 7d56ccb | 2012-10-01 17:56:58 -0700 | [diff] [blame] | 47 | #define __need_NULL |
| 48 | #include <stddef.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 49 | |
Elliott Hughes | fd936ae | 2016-08-12 10:16:34 -0700 | [diff] [blame] | 50 | #include <bits/seek_constants.h> |
| 51 | |
Dan Albert | 3037ea4 | 2016-10-06 15:46:45 -0700 | [diff] [blame^] | 52 | #if __ANDROID_API__ <= 23 |
| 53 | #include <bits/struct_file.h> |
| 54 | #endif |
| 55 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 56 | __BEGIN_DECLS |
| 57 | |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 58 | #if defined(__clang__) |
| 59 | #pragma clang diagnostic push |
| 60 | #pragma clang diagnostic ignored "-Wnullability-completeness" |
| 61 | #endif |
| 62 | |
Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 63 | typedef off_t fpos_t; |
| 64 | typedef off64_t fpos64_t; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 65 | |
Elliott Hughes | f0141df | 2015-10-12 12:44:23 -0700 | [diff] [blame] | 66 | struct __sFILE; |
| 67 | typedef struct __sFILE FILE; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 68 | |
Dan Albert | 32c79c2 | 2016-07-15 11:32:23 -0700 | [diff] [blame] | 69 | #if __ANDROID_API__ >= 23 |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 70 | extern FILE* stdin __INTRODUCED_IN(23); |
| 71 | extern FILE* stdout __INTRODUCED_IN(23); |
| 72 | extern FILE* stderr __INTRODUCED_IN(23); |
Dan Albert | 32c79c2 | 2016-07-15 11:32:23 -0700 | [diff] [blame] | 73 | |
Elliott Hughes | 168667c | 2014-11-14 14:42:59 -0800 | [diff] [blame] | 74 | /* C99 and earlier plus current C++ standards say these must be macros. */ |
| 75 | #define stdin stdin |
| 76 | #define stdout stdout |
| 77 | #define stderr stderr |
Dan Albert | 32c79c2 | 2016-07-15 11:32:23 -0700 | [diff] [blame] | 78 | #else |
| 79 | /* Before M the actual symbols for stdin and friends had different names. */ |
Dan Albert | 3037ea4 | 2016-10-06 15:46:45 -0700 | [diff] [blame^] | 80 | extern FILE __sF[] __REMOVED_IN(23); |
Dan Albert | 32c79c2 | 2016-07-15 11:32:23 -0700 | [diff] [blame] | 81 | |
Dan Albert | 3037ea4 | 2016-10-06 15:46:45 -0700 | [diff] [blame^] | 82 | #define stdin (&__sF[0]) |
| 83 | #define stdout (&__sF[1]) |
| 84 | #define stderr (&__sF[2]) |
Dan Albert | 32c79c2 | 2016-07-15 11:32:23 -0700 | [diff] [blame] | 85 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 86 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 87 | /* |
| 88 | * The following three definitions are for ANSI C, which took them |
| 89 | * from System V, which brilliantly took internal interface macros and |
| 90 | * made them official arguments to setvbuf(), without renaming them. |
| 91 | * Hence, these ugly _IOxxx names are *supposed* to appear in user code. |
| 92 | * |
| 93 | * Although numbered as their counterparts above, the implementation |
| 94 | * does not rely on this. |
| 95 | */ |
| 96 | #define _IOFBF 0 /* setvbuf should set fully buffered */ |
| 97 | #define _IOLBF 1 /* setvbuf should set line buffered */ |
| 98 | #define _IONBF 2 /* setvbuf should set unbuffered */ |
| 99 | |
| 100 | #define BUFSIZ 1024 /* size of buffer used by setbuf */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 101 | #define EOF (-1) |
| 102 | |
| 103 | /* |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 104 | * FOPEN_MAX is a minimum maximum, and is the number of streams that |
| 105 | * stdio can provide without attempting to allocate further resources |
| 106 | * (which could fail). Do not use this for anything. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 107 | */ |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 108 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 109 | #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ |
| 110 | #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ |
| 111 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 112 | #define L_tmpnam 1024 /* XXX must be == PATH_MAX */ |
| 113 | #define TMP_MAX 308915776 |
| 114 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 115 | /* |
| 116 | * Functions defined in ANSI C standard. |
| 117 | */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 118 | void clearerr(FILE *); |
| 119 | int fclose(FILE *); |
| 120 | int feof(FILE *); |
| 121 | int ferror(FILE *); |
| 122 | int fflush(FILE *); |
| 123 | int fgetc(FILE *); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 124 | char *fgets(char * __restrict, int, FILE * __restrict); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 125 | int fprintf(FILE * __restrict , const char * __restrict _Nonnull, ...) __printflike(2, 3); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 126 | int fputc(int, FILE *); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 127 | int fputs(const char * __restrict, FILE * __restrict); |
| 128 | size_t fread(void * __restrict, size_t, size_t, FILE * __restrict); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 129 | int fscanf(FILE * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 130 | size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 131 | int getc(FILE *); |
| 132 | int getchar(void); |
Josh Gao | 46b4416 | 2016-05-27 11:14:16 -0700 | [diff] [blame] | 133 | ssize_t getdelim(char** __restrict, size_t* __restrict, int, FILE* __restrict) __INTRODUCED_IN(18); |
| 134 | ssize_t getline(char** __restrict, size_t* __restrict, FILE* __restrict) __INTRODUCED_IN(18); |
Elliott Hughes | c13fb75 | 2013-12-17 20:43:30 -0800 | [diff] [blame] | 135 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 136 | void perror(const char *); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 137 | int printf(const char * __restrict _Nonnull, ...) __printflike(1, 2); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 138 | int putc(int, FILE *); |
| 139 | int putchar(int); |
| 140 | int puts(const char *); |
| 141 | int remove(const char *); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 142 | void rewind(FILE *); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 143 | int scanf(const char * __restrict _Nonnull, ...) __scanflike(1, 2); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 144 | void setbuf(FILE * __restrict, char * __restrict); |
| 145 | int setvbuf(FILE * __restrict, char * __restrict, int, size_t); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 146 | int sscanf(const char * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 147 | int ungetc(int, FILE *); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 148 | int vfprintf(FILE * __restrict, const char * __restrict _Nonnull, __va_list) __printflike(2, 0); |
| 149 | int vprintf(const char * __restrict _Nonnull, __va_list) __printflike(1, 0); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 150 | |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 151 | int dprintf(int, const char* __restrict _Nonnull, ...) __printflike(2, 3) __INTRODUCED_IN(21); |
| 152 | int vdprintf(int, const char* __restrict _Nonnull, __va_list) __printflike(2, 0) __INTRODUCED_IN(21); |
Elliott Hughes | fcac8ff | 2014-05-22 01:24:30 -0700 | [diff] [blame] | 153 | |
Elliott Hughes | f6495c7 | 2016-07-25 09:20:57 -0700 | [diff] [blame] | 154 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \ |
| 155 | (defined(__cplusplus) && __cplusplus <= 201103L) |
Yabin Cui | 9b4f77f | 2015-02-23 16:42:07 -0800 | [diff] [blame] | 156 | char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead"))); |
Dan Albert | 9635046 | 2014-06-17 23:31:21 +0000 | [diff] [blame] | 157 | #endif |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 158 | int sprintf(char* __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3); |
| 159 | int vsprintf(char* __restrict, const char* __restrict _Nonnull, __va_list) __printflike(2, 0); |
Yabin Cui | 9b4f77f | 2015-02-23 16:42:07 -0800 | [diff] [blame] | 160 | char* tmpnam(char*) __attribute__((deprecated("tmpnam is unsafe, use mkstemp or tmpfile instead"))); |
Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 161 | #define P_tmpdir "/tmp/" /* deprecated */ |
Elliott Hughes | c13fb75 | 2013-12-17 20:43:30 -0800 | [diff] [blame] | 162 | char* tempnam(const char*, const char*) |
Yabin Cui | 9b4f77f | 2015-02-23 16:42:07 -0800 | [diff] [blame] | 163 | __attribute__((deprecated("tempnam is unsafe, use mkstemp or tmpfile instead"))); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 164 | |
Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 165 | int rename(const char*, const char*); |
| 166 | int renameat(int, const char*, int, const char*); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 167 | |
Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 168 | int fseek(FILE*, long, int); |
| 169 | long ftell(FILE*); |
Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 170 | |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 171 | #if defined(__USE_FILE_OFFSET64) |
Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 172 | int fgetpos(FILE*, fpos_t*) __RENAME(fgetpos64); |
| 173 | int fsetpos(FILE*, const fpos_t*) __RENAME(fsetpos64); |
| 174 | int fseeko(FILE*, off_t, int) __RENAME(fseeko64); |
| 175 | off_t ftello(FILE*) __RENAME(ftello64); |
Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 176 | # if defined(__USE_BSD) |
| 177 | FILE* funopen(const void*, |
| 178 | int (*)(void*, char*, int), |
| 179 | int (*)(void*, const char*, int), |
| 180 | fpos_t (*)(void*, fpos_t, int), |
| 181 | int (*)(void*)) __RENAME(funopen64); |
| 182 | # endif |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 183 | #else |
Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 184 | int fgetpos(FILE*, fpos_t*); |
| 185 | int fsetpos(FILE*, const fpos_t*); |
| 186 | int fseeko(FILE*, off_t, int); |
| 187 | off_t ftello(FILE*); |
Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 188 | # if defined(__USE_BSD) |
| 189 | FILE* funopen(const void*, |
| 190 | int (*)(void*, char*, int), |
| 191 | int (*)(void*, const char*, int), |
| 192 | fpos_t (*)(void*, fpos_t, int), |
| 193 | int (*)(void*)); |
| 194 | # endif |
Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 195 | #endif |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 196 | int fgetpos64(FILE*, fpos64_t*) __INTRODUCED_IN(24); |
| 197 | int fsetpos64(FILE*, const fpos64_t*) __INTRODUCED_IN(24); |
| 198 | int fseeko64(FILE*, off64_t, int) __INTRODUCED_IN(24); |
| 199 | off64_t ftello64(FILE*) __INTRODUCED_IN(24); |
Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 200 | #if defined(__USE_BSD) |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 201 | FILE* funopen64(const void*, int (*)(void*, char*, int), int (*)(void*, const char*, int), |
| 202 | fpos64_t (*)(void*, fpos64_t, int), int (*)(void*)) __INTRODUCED_IN(24); |
Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 203 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 204 | |
Elliott Hughes | f226ee5 | 2016-02-03 11:24:28 -0800 | [diff] [blame] | 205 | FILE* fopen(const char* __restrict, const char* __restrict); |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 206 | FILE* fopen64(const char* __restrict, const char* __restrict) __INTRODUCED_IN(24); |
Elliott Hughes | f226ee5 | 2016-02-03 11:24:28 -0800 | [diff] [blame] | 207 | FILE* freopen(const char* __restrict, const char* __restrict, FILE* __restrict); |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 208 | FILE* freopen64(const char* __restrict, const char* __restrict, FILE* __restrict) |
| 209 | __INTRODUCED_IN(24); |
Elliott Hughes | f226ee5 | 2016-02-03 11:24:28 -0800 | [diff] [blame] | 210 | FILE* tmpfile(void); |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 211 | FILE* tmpfile64(void) __INTRODUCED_IN(24); |
Elliott Hughes | f226ee5 | 2016-02-03 11:24:28 -0800 | [diff] [blame] | 212 | |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 213 | int snprintf(char* __restrict, size_t, const char* __restrict _Nonnull, ...) __printflike(3, 4); |
| 214 | int vfscanf(FILE* __restrict, const char* __restrict _Nonnull, __va_list) __scanflike(2, 0); |
| 215 | int vscanf(const char* _Nonnull , __va_list) __scanflike(1, 0); |
| 216 | int vsnprintf(char* __restrict, size_t, const char* __restrict _Nonnull, __va_list) __printflike(3, 0); |
| 217 | int vsscanf(const char* __restrict _Nonnull, const char* __restrict _Nonnull, __va_list) __scanflike(2, 0); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 218 | |
Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 219 | #define L_ctermid 1024 /* size for ctermid() */ |
Josh Gao | 95fa26e | 2016-06-10 16:33:05 -0700 | [diff] [blame] | 220 | char* ctermid(char*) __INTRODUCED_IN_FUTURE; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 221 | |
Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 222 | FILE* fdopen(int, const char*); |
| 223 | int fileno(FILE*); |
| 224 | int pclose(FILE*); |
| 225 | FILE* popen(const char*, const char*); |
| 226 | void flockfile(FILE*); |
| 227 | int ftrylockfile(FILE*); |
| 228 | void funlockfile(FILE*); |
| 229 | int getc_unlocked(FILE*); |
| 230 | int getchar_unlocked(void); |
| 231 | int putc_unlocked(int, FILE*); |
| 232 | int putchar_unlocked(int); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 233 | |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 234 | FILE* fmemopen(void*, size_t, const char*) __INTRODUCED_IN(23); |
| 235 | FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 236 | |
Elliott Hughes | 9c8d711 | 2016-06-13 13:23:42 -0700 | [diff] [blame] | 237 | #if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */ |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 238 | int asprintf(char** __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3); |
Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 239 | char* fgetln(FILE* __restrict, size_t* __restrict); |
| 240 | int fpurge(FILE*); |
| 241 | void setbuffer(FILE*, char*, int); |
| 242 | int setlinebuf(FILE*); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 243 | int vasprintf(char** __restrict, const char* __restrict _Nonnull, __va_list) __printflike(2, 0); |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 244 | void clearerr_unlocked(FILE*) __INTRODUCED_IN(23); |
| 245 | int feof_unlocked(FILE*) __INTRODUCED_IN(23); |
| 246 | int ferror_unlocked(FILE*) __INTRODUCED_IN(23); |
| 247 | int fileno_unlocked(FILE*) __INTRODUCED_IN(24); |
Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 248 | #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) |
| 249 | #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) |
Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 250 | #endif /* __USE_BSD */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 251 | |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 252 | char* __fgets_chk(char*, int, FILE*, size_t) __INTRODUCED_IN(17); |
| 253 | char* __fgets_real(char*, int, FILE*) __RENAME(fgets); |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 254 | __errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer"); |
| 255 | __errordecl(__fgets_too_small_error, "fgets called with size less than zero"); |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 256 | |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 257 | size_t __fread_chk(void* __restrict, size_t, size_t, FILE* __restrict, size_t) |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 258 | __INTRODUCED_IN(24); |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 259 | size_t __fread_real(void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fread); |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 260 | __errordecl(__fread_too_big_error, "fread called with size * count bigger than buffer"); |
| 261 | __errordecl(__fread_overflow, "fread called with overflowing size * count"); |
| 262 | |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 263 | size_t __fwrite_chk(const void* __restrict, size_t, size_t, FILE* __restrict, size_t) |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 264 | __INTRODUCED_IN(24); |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 265 | size_t __fwrite_real(const void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fwrite); |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 266 | __errordecl(__fwrite_too_big_error, "fwrite called with size * count bigger than buffer"); |
| 267 | __errordecl(__fwrite_overflow, "fwrite called with overflowing size * count"); |
| 268 | |
Elliott Hughes | 53cf348 | 2016-08-09 13:06:41 -0700 | [diff] [blame] | 269 | #if defined(__BIONIC_FORTIFY) && !defined(__BIONIC_NO_STDIO_FORTIFY) |
Elliott Hughes | ce45fea | 2012-10-22 16:10:27 -0700 | [diff] [blame] | 270 | |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 271 | #if __ANDROID_API__ >= 17 |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 272 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 273 | __printflike(3, 0) int vsnprintf(char* dest, size_t size, const char* _Nonnull format, __va_list ap) { |
Nick Kralevich | 9020fd5 | 2013-04-30 11:31:35 -0700 | [diff] [blame] | 274 | return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap); |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 277 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 278 | __printflike(2, 0) int vsprintf(char* dest, const char* _Nonnull format, __va_list ap) { |
Nick Kralevich | 9020fd5 | 2013-04-30 11:31:35 -0700 | [diff] [blame] | 279 | return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap); |
Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Nick Kralevich | 621b19d | 2013-06-25 10:02:35 -0700 | [diff] [blame] | 282 | #if defined(__clang__) |
Nick Kralevich | 7eb28b5 | 2014-03-18 17:03:38 -0700 | [diff] [blame] | 283 | #if !defined(snprintf) |
| 284 | #define __wrap_snprintf(dest, size, ...) __builtin___snprintf_chk(dest, size, 0, __bos(dest), __VA_ARGS__) |
| 285 | #define snprintf(...) __wrap_snprintf(__VA_ARGS__) |
| 286 | #endif |
Nick Kralevich | 621b19d | 2013-06-25 10:02:35 -0700 | [diff] [blame] | 287 | #else |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 288 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 289 | __printflike(3, 4) int snprintf(char* dest, size_t size, const char* _Nonnull format, ...) { |
| 290 | return __builtin___snprintf_chk(dest, size, 0, __bos(dest), format, __builtin_va_arg_pack()); |
Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 291 | } |
Nick Kralevich | 621b19d | 2013-06-25 10:02:35 -0700 | [diff] [blame] | 292 | #endif |
Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 293 | |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 294 | #if defined(__clang__) |
Nick Kralevich | 7eb28b5 | 2014-03-18 17:03:38 -0700 | [diff] [blame] | 295 | #if !defined(sprintf) |
| 296 | #define __wrap_sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__) |
| 297 | #define sprintf(...) __wrap_sprintf(__VA_ARGS__) |
| 298 | #endif |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 299 | #else |
Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 300 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 301 | __printflike(2, 3) int sprintf(char* dest, const char* _Nonnull format, ...) { |
| 302 | return __builtin___sprintf_chk(dest, 0, __bos(dest), format, __builtin_va_arg_pack()); |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 303 | } |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 304 | #endif |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 305 | #endif /* __ANDROID_API__ >= 17 */ |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 306 | |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 307 | #if __ANDROID_API__ >= 24 |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 308 | __BIONIC_FORTIFY_INLINE |
| 309 | size_t fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) { |
| 310 | size_t bos = __bos0(buf); |
| 311 | |
| 312 | #if !defined(__clang__) |
| 313 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 314 | return __fread_real(buf, size, count, stream); |
| 315 | } |
| 316 | |
| 317 | if (__builtin_constant_p(size) && __builtin_constant_p(count)) { |
| 318 | size_t total; |
| 319 | if (__size_mul_overflow(size, count, &total)) { |
| 320 | __fread_overflow(); |
| 321 | } |
| 322 | |
| 323 | if (total > bos) { |
| 324 | __fread_too_big_error(); |
| 325 | } |
| 326 | |
| 327 | return __fread_real(buf, size, count, stream); |
| 328 | } |
| 329 | #endif |
| 330 | |
| 331 | return __fread_chk(buf, size, count, stream, bos); |
| 332 | } |
| 333 | |
| 334 | __BIONIC_FORTIFY_INLINE |
| 335 | size_t fwrite(const void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) { |
| 336 | size_t bos = __bos0(buf); |
| 337 | |
| 338 | #if !defined(__clang__) |
| 339 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 340 | return __fwrite_real(buf, size, count, stream); |
| 341 | } |
| 342 | |
| 343 | if (__builtin_constant_p(size) && __builtin_constant_p(count)) { |
| 344 | size_t total; |
| 345 | if (__size_mul_overflow(size, count, &total)) { |
| 346 | __fwrite_overflow(); |
| 347 | } |
| 348 | |
| 349 | if (total > bos) { |
| 350 | __fwrite_too_big_error(); |
| 351 | } |
| 352 | |
| 353 | return __fwrite_real(buf, size, count, stream); |
| 354 | } |
| 355 | #endif |
| 356 | |
| 357 | return __fwrite_chk(buf, size, count, stream, bos); |
| 358 | } |
Dan Albert | dfa6bbb | 2016-08-02 15:08:32 -0700 | [diff] [blame] | 359 | #endif /* __ANDROID_API__ >= 24 */ |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 360 | |
Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 361 | #if !defined(__clang__) |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 362 | |
| 363 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 364 | char *fgets(char* dest, int size, FILE* stream) { |
Nick Kralevich | 9020fd5 | 2013-04-30 11:31:35 -0700 | [diff] [blame] | 365 | size_t bos = __bos(dest); |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 366 | |
| 367 | // Compiler can prove, at compile time, that the passed in size |
| 368 | // is always negative. Force a compiler error. |
| 369 | if (__builtin_constant_p(size) && (size < 0)) { |
| 370 | __fgets_too_small_error(); |
| 371 | } |
| 372 | |
| 373 | // Compiler doesn't know destination size. Don't call __fgets_chk |
Nick Kralevich | 9b6cc22 | 2012-07-13 14:46:36 -0700 | [diff] [blame] | 374 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 375 | return __fgets_real(dest, size, stream); |
| 376 | } |
| 377 | |
| 378 | // Compiler can prove, at compile time, that the passed in size |
| 379 | // is always <= the actual object size. Don't call __fgets_chk |
Elliott Hughes | 41b3179 | 2013-01-28 10:36:31 -0800 | [diff] [blame] | 380 | if (__builtin_constant_p(size) && (size <= (int) bos)) { |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 381 | return __fgets_real(dest, size, stream); |
| 382 | } |
| 383 | |
| 384 | // Compiler can prove, at compile time, that the passed in size |
| 385 | // is always > the actual object size. Force a compiler error. |
Elliott Hughes | 41b3179 | 2013-01-28 10:36:31 -0800 | [diff] [blame] | 386 | if (__builtin_constant_p(size) && (size > (int) bos)) { |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 387 | __fgets_too_big_error(); |
| 388 | } |
| 389 | |
| 390 | return __fgets_chk(dest, size, stream, bos); |
| 391 | } |
| 392 | |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 393 | #endif /* !defined(__clang__) */ |
| 394 | |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 395 | #endif /* defined(__BIONIC_FORTIFY) */ |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 396 | |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 397 | #if defined(__clang__) |
| 398 | #pragma clang diagnostic pop |
| 399 | #endif |
| 400 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 401 | __END_DECLS |
| 402 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 403 | #endif /* _STDIO_H_ */ |