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 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 50 | __BEGIN_DECLS |
| 51 | |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 52 | #if defined(__clang__) |
| 53 | #pragma clang diagnostic push |
| 54 | #pragma clang diagnostic ignored "-Wnullability-completeness" |
| 55 | #endif |
| 56 | |
Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 57 | typedef off_t fpos_t; |
| 58 | typedef off64_t fpos64_t; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 59 | |
Elliott Hughes | f0141df | 2015-10-12 12:44:23 -0700 | [diff] [blame] | 60 | struct __sFILE; |
| 61 | typedef struct __sFILE FILE; |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 62 | |
Dan Albert | 32c79c2 | 2016-07-15 11:32:23 -0700 | [diff] [blame] | 63 | #if __ANDROID_API__ >= 23 |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 64 | extern FILE* stdin __INTRODUCED_IN(23); |
| 65 | extern FILE* stdout __INTRODUCED_IN(23); |
| 66 | extern FILE* stderr __INTRODUCED_IN(23); |
Dan Albert | 32c79c2 | 2016-07-15 11:32:23 -0700 | [diff] [blame] | 67 | |
Elliott Hughes | 168667c | 2014-11-14 14:42:59 -0800 | [diff] [blame] | 68 | /* C99 and earlier plus current C++ standards say these must be macros. */ |
| 69 | #define stdin stdin |
| 70 | #define stdout stdout |
| 71 | #define stderr stderr |
Dan Albert | 32c79c2 | 2016-07-15 11:32:23 -0700 | [diff] [blame] | 72 | #else |
| 73 | /* Before M the actual symbols for stdin and friends had different names. */ |
| 74 | extern FILE* __sF[] __REMOVED_IN(23); |
| 75 | |
| 76 | #define stdin __sF[0] |
| 77 | #define stdout __sF[1] |
| 78 | #define stderr __sF[2] |
| 79 | #endif |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 80 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 | /* |
| 82 | * The following three definitions are for ANSI C, which took them |
| 83 | * from System V, which brilliantly took internal interface macros and |
| 84 | * made them official arguments to setvbuf(), without renaming them. |
| 85 | * Hence, these ugly _IOxxx names are *supposed* to appear in user code. |
| 86 | * |
| 87 | * Although numbered as their counterparts above, the implementation |
| 88 | * does not rely on this. |
| 89 | */ |
| 90 | #define _IOFBF 0 /* setvbuf should set fully buffered */ |
| 91 | #define _IOLBF 1 /* setvbuf should set line buffered */ |
| 92 | #define _IONBF 2 /* setvbuf should set unbuffered */ |
| 93 | |
| 94 | #define BUFSIZ 1024 /* size of buffer used by setbuf */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 95 | #define EOF (-1) |
| 96 | |
| 97 | /* |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 98 | * FOPEN_MAX is a minimum maximum, and is the number of streams that |
| 99 | * stdio can provide without attempting to allocate further resources |
| 100 | * (which could fail). Do not use this for anything. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 101 | */ |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 102 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 103 | #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */ |
| 104 | #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */ |
| 105 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 106 | #define L_tmpnam 1024 /* XXX must be == PATH_MAX */ |
| 107 | #define TMP_MAX 308915776 |
| 108 | |
Elliott Hughes | 1ed337d | 2015-02-02 14:02:09 -0800 | [diff] [blame] | 109 | #define SEEK_SET 0 |
| 110 | #define SEEK_CUR 1 |
| 111 | #define SEEK_END 2 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 112 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 113 | /* |
| 114 | * Functions defined in ANSI C standard. |
| 115 | */ |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 116 | void clearerr(FILE *); |
| 117 | int fclose(FILE *); |
| 118 | int feof(FILE *); |
| 119 | int ferror(FILE *); |
| 120 | int fflush(FILE *); |
| 121 | int fgetc(FILE *); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 122 | char *fgets(char * __restrict, int, FILE * __restrict); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 123 | 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] | 124 | int fputc(int, FILE *); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 125 | int fputs(const char * __restrict, FILE * __restrict); |
| 126 | size_t fread(void * __restrict, size_t, size_t, FILE * __restrict); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 127 | int fscanf(FILE * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 128 | 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] | 129 | int getc(FILE *); |
| 130 | int getchar(void); |
Josh Gao | 46b4416 | 2016-05-27 11:14:16 -0700 | [diff] [blame] | 131 | ssize_t getdelim(char** __restrict, size_t* __restrict, int, FILE* __restrict) __INTRODUCED_IN(18); |
| 132 | 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] | 133 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 134 | void perror(const char *); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 135 | int printf(const char * __restrict _Nonnull, ...) __printflike(1, 2); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 136 | int putc(int, FILE *); |
| 137 | int putchar(int); |
| 138 | int puts(const char *); |
| 139 | int remove(const char *); |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 140 | void rewind(FILE *); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 141 | int scanf(const char * __restrict _Nonnull, ...) __scanflike(1, 2); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 142 | void setbuf(FILE * __restrict, char * __restrict); |
| 143 | int setvbuf(FILE * __restrict, char * __restrict, int, size_t); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 144 | 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] | 145 | int ungetc(int, FILE *); |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 146 | int vfprintf(FILE * __restrict, const char * __restrict _Nonnull, __va_list) __printflike(2, 0); |
| 147 | int vprintf(const char * __restrict _Nonnull, __va_list) __printflike(1, 0); |
Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 148 | |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 149 | int dprintf(int, const char* __restrict _Nonnull, ...) __printflike(2, 3) __INTRODUCED_IN(21); |
| 150 | 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] | 151 | |
Elliott Hughes | f6495c7 | 2016-07-25 09:20:57 -0700 | [diff] [blame^] | 152 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \ |
| 153 | (defined(__cplusplus) && __cplusplus <= 201103L) |
Yabin Cui | 9b4f77f | 2015-02-23 16:42:07 -0800 | [diff] [blame] | 154 | char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead"))); |
Dan Albert | 9635046 | 2014-06-17 23:31:21 +0000 | [diff] [blame] | 155 | #endif |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 156 | int sprintf(char* __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3); |
| 157 | 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] | 158 | 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] | 159 | #if defined(__USE_BSD) || defined(__USE_GNU) |
| 160 | #define P_tmpdir "/tmp/" /* deprecated */ |
Elliott Hughes | c13fb75 | 2013-12-17 20:43:30 -0800 | [diff] [blame] | 161 | char* tempnam(const char*, const char*) |
Yabin Cui | 9b4f77f | 2015-02-23 16:42:07 -0800 | [diff] [blame] | 162 | __attribute__((deprecated("tempnam is unsafe, use mkstemp or tmpfile instead"))); |
Elliott Hughes | c13fb75 | 2013-12-17 20:43:30 -0800 | [diff] [blame] | 163 | #endif |
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 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 269 | #if defined(__BIONIC_FORTIFY) |
Elliott Hughes | ce45fea | 2012-10-22 16:10:27 -0700 | [diff] [blame] | 270 | |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 271 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 272 | __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] | 273 | return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap); |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 276 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 277 | __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] | 278 | return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap); |
Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Nick Kralevich | 621b19d | 2013-06-25 10:02:35 -0700 | [diff] [blame] | 281 | #if defined(__clang__) |
Nick Kralevich | 7eb28b5 | 2014-03-18 17:03:38 -0700 | [diff] [blame] | 282 | #if !defined(snprintf) |
| 283 | #define __wrap_snprintf(dest, size, ...) __builtin___snprintf_chk(dest, size, 0, __bos(dest), __VA_ARGS__) |
| 284 | #define snprintf(...) __wrap_snprintf(__VA_ARGS__) |
| 285 | #endif |
Nick Kralevich | 621b19d | 2013-06-25 10:02:35 -0700 | [diff] [blame] | 286 | #else |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 287 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 288 | __printflike(3, 4) int snprintf(char* dest, size_t size, const char* _Nonnull format, ...) { |
| 289 | 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] | 290 | } |
Nick Kralevich | 621b19d | 2013-06-25 10:02:35 -0700 | [diff] [blame] | 291 | #endif |
Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 292 | |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 293 | #if defined(__clang__) |
Nick Kralevich | 7eb28b5 | 2014-03-18 17:03:38 -0700 | [diff] [blame] | 294 | #if !defined(sprintf) |
| 295 | #define __wrap_sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__) |
| 296 | #define sprintf(...) __wrap_sprintf(__VA_ARGS__) |
| 297 | #endif |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 298 | #else |
Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 299 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 300 | __printflike(2, 3) int sprintf(char* dest, const char* _Nonnull format, ...) { |
| 301 | 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] | 302 | } |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 303 | #endif |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 304 | |
Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 305 | __BIONIC_FORTIFY_INLINE |
| 306 | size_t fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) { |
| 307 | size_t bos = __bos0(buf); |
| 308 | |
| 309 | #if !defined(__clang__) |
| 310 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 311 | return __fread_real(buf, size, count, stream); |
| 312 | } |
| 313 | |
| 314 | if (__builtin_constant_p(size) && __builtin_constant_p(count)) { |
| 315 | size_t total; |
| 316 | if (__size_mul_overflow(size, count, &total)) { |
| 317 | __fread_overflow(); |
| 318 | } |
| 319 | |
| 320 | if (total > bos) { |
| 321 | __fread_too_big_error(); |
| 322 | } |
| 323 | |
| 324 | return __fread_real(buf, size, count, stream); |
| 325 | } |
| 326 | #endif |
| 327 | |
| 328 | return __fread_chk(buf, size, count, stream, bos); |
| 329 | } |
| 330 | |
| 331 | __BIONIC_FORTIFY_INLINE |
| 332 | size_t fwrite(const void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) { |
| 333 | size_t bos = __bos0(buf); |
| 334 | |
| 335 | #if !defined(__clang__) |
| 336 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
| 337 | return __fwrite_real(buf, size, count, stream); |
| 338 | } |
| 339 | |
| 340 | if (__builtin_constant_p(size) && __builtin_constant_p(count)) { |
| 341 | size_t total; |
| 342 | if (__size_mul_overflow(size, count, &total)) { |
| 343 | __fwrite_overflow(); |
| 344 | } |
| 345 | |
| 346 | if (total > bos) { |
| 347 | __fwrite_too_big_error(); |
| 348 | } |
| 349 | |
| 350 | return __fwrite_real(buf, size, count, stream); |
| 351 | } |
| 352 | #endif |
| 353 | |
| 354 | return __fwrite_chk(buf, size, count, stream, bos); |
| 355 | } |
| 356 | |
Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 357 | #if !defined(__clang__) |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 358 | |
| 359 | __BIONIC_FORTIFY_INLINE |
Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 360 | char *fgets(char* dest, int size, FILE* stream) { |
Nick Kralevich | 9020fd5 | 2013-04-30 11:31:35 -0700 | [diff] [blame] | 361 | size_t bos = __bos(dest); |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 362 | |
| 363 | // Compiler can prove, at compile time, that the passed in size |
| 364 | // is always negative. Force a compiler error. |
| 365 | if (__builtin_constant_p(size) && (size < 0)) { |
| 366 | __fgets_too_small_error(); |
| 367 | } |
| 368 | |
| 369 | // Compiler doesn't know destination size. Don't call __fgets_chk |
Nick Kralevich | 9b6cc22 | 2012-07-13 14:46:36 -0700 | [diff] [blame] | 370 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 371 | return __fgets_real(dest, size, stream); |
| 372 | } |
| 373 | |
| 374 | // Compiler can prove, at compile time, that the passed in size |
| 375 | // is always <= the actual object size. Don't call __fgets_chk |
Elliott Hughes | 41b3179 | 2013-01-28 10:36:31 -0800 | [diff] [blame] | 376 | if (__builtin_constant_p(size) && (size <= (int) bos)) { |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 377 | return __fgets_real(dest, size, stream); |
| 378 | } |
| 379 | |
| 380 | // Compiler can prove, at compile time, that the passed in size |
| 381 | // is always > the actual object size. Force a compiler error. |
Elliott Hughes | 41b3179 | 2013-01-28 10:36:31 -0800 | [diff] [blame] | 382 | if (__builtin_constant_p(size) && (size > (int) bos)) { |
Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 383 | __fgets_too_big_error(); |
| 384 | } |
| 385 | |
| 386 | return __fgets_chk(dest, size, stream, bos); |
| 387 | } |
| 388 | |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 389 | #endif /* !defined(__clang__) */ |
| 390 | |
Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 391 | #endif /* defined(__BIONIC_FORTIFY) */ |
Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 392 | |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 393 | #if defined(__clang__) |
| 394 | #pragma clang diagnostic pop |
| 395 | #endif |
| 396 | |
Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 397 | __END_DECLS |
| 398 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 399 | #endif /* _STDIO_H_ */ |