| 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 |  | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 52 | #if __ANDROID_API__ < __ANDROID_API_N__ | 
| Dan Albert | 3037ea4 | 2016-10-06 15:46:45 -0700 | [diff] [blame] | 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 |  | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 69 | #if __ANDROID_API__ >= __ANDROID_API_M__ | 
| 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 *); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 124 | char	*fgets(char * __restrict, int, FILE * __restrict) __overloadable | 
|  | 125 | __RENAME_CLANG(fgets); | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 126 | 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] | 127 | int	 fputc(int, FILE *); | 
| Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 128 | int	 fputs(const char * __restrict, FILE * __restrict); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 129 | size_t	 fread(void * __restrict, size_t, size_t, FILE * __restrict) | 
|  | 130 | __overloadable __RENAME_CLANG(fread); | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 131 | int	 fscanf(FILE * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 132 | size_t	 fwrite(const void * __restrict, size_t, size_t, FILE * __restrict) | 
|  | 133 | __overloadable __RENAME_CLANG(fwrite); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 134 | int	 getc(FILE *); | 
|  | 135 | int	 getchar(void); | 
| Josh Gao | 46b4416 | 2016-05-27 11:14:16 -0700 | [diff] [blame] | 136 | ssize_t getdelim(char** __restrict, size_t* __restrict, int, FILE* __restrict) __INTRODUCED_IN(18); | 
|  | 137 | 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] | 138 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 139 | void	 perror(const char *); | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 140 | int	 printf(const char * __restrict _Nonnull, ...) __printflike(1, 2); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 141 | int	 putc(int, FILE *); | 
|  | 142 | int	 putchar(int); | 
|  | 143 | int	 puts(const char *); | 
|  | 144 | int	 remove(const char *); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 145 | void	 rewind(FILE *); | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 146 | int	 scanf(const char * __restrict _Nonnull, ...) __scanflike(1, 2); | 
| Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 147 | void	 setbuf(FILE * __restrict, char * __restrict); | 
|  | 148 | int	 setvbuf(FILE * __restrict, char * __restrict, int, size_t); | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 149 | 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] | 150 | int	 ungetc(int, FILE *); | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 151 | int	 vfprintf(FILE * __restrict, const char * __restrict _Nonnull, __va_list) __printflike(2, 0); | 
|  | 152 | int	 vprintf(const char * __restrict _Nonnull, __va_list) __printflike(1, 0); | 
| Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 153 |  | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 154 | int dprintf(int, const char* __restrict _Nonnull, ...) __printflike(2, 3) __INTRODUCED_IN(21); | 
|  | 155 | 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] | 156 |  | 
| Elliott Hughes | f6495c7 | 2016-07-25 09:20:57 -0700 | [diff] [blame] | 157 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \ | 
|  | 158 | (defined(__cplusplus) && __cplusplus <= 201103L) | 
| Yabin Cui | 9b4f77f | 2015-02-23 16:42:07 -0800 | [diff] [blame] | 159 | char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead"))); | 
| Dan Albert | 9635046 | 2014-06-17 23:31:21 +0000 | [diff] [blame] | 160 | #endif | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 161 | int sprintf(char* __restrict, const char* __restrict _Nonnull, ...) | 
|  | 162 | __printflike(2, 3) __warnattr_strict("sprintf is often misused; please use snprintf") | 
|  | 163 | __overloadable __RENAME_CLANG(sprintf); | 
|  | 164 | int vsprintf(char* __restrict, const char* __restrict _Nonnull, __va_list) | 
|  | 165 | __overloadable __printflike(2, 0) __RENAME_CLANG(vsprintf) | 
|  | 166 | __warnattr_strict("vsprintf is often misused; please use vsnprintf"); | 
|  | 167 | char* tmpnam(char*) | 
|  | 168 | __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead"); | 
| Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 169 | #define P_tmpdir "/tmp/" /* deprecated */ | 
| Elliott Hughes | c13fb75 | 2013-12-17 20:43:30 -0800 | [diff] [blame] | 170 | char* tempnam(const char*, const char*) | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 171 | __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead"); | 
| Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 172 |  | 
| Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 173 | int rename(const char*, const char*); | 
|  | 174 | int renameat(int, const char*, int, const char*); | 
| Elliott Hughes | d04c183 | 2013-05-14 16:08:43 -0700 | [diff] [blame] | 175 |  | 
| Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 176 | int fseek(FILE*, long, int); | 
|  | 177 | long ftell(FILE*); | 
| Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 178 |  | 
| Elliott Hughes | 79a3db0 | 2017-03-17 18:56:08 -0700 | [diff] [blame] | 179 | #if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= __ANDROID_API_N__ | 
| Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 180 | int fgetpos(FILE*, fpos_t*) __RENAME(fgetpos64); | 
|  | 181 | int fsetpos(FILE*, const fpos_t*) __RENAME(fsetpos64); | 
|  | 182 | int fseeko(FILE*, off_t, int) __RENAME(fseeko64); | 
|  | 183 | off_t ftello(FILE*) __RENAME(ftello64); | 
| Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 184 | #  if defined(__USE_BSD) | 
|  | 185 | FILE* funopen(const void*, | 
|  | 186 | int (*)(void*, char*, int), | 
|  | 187 | int (*)(void*, const char*, int), | 
|  | 188 | fpos_t (*)(void*, fpos_t, int), | 
|  | 189 | int (*)(void*)) __RENAME(funopen64); | 
|  | 190 | #  endif | 
| Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 191 | #else | 
| Elliott Hughes | 9677fab | 2016-01-25 15:50:59 -0800 | [diff] [blame] | 192 | int fgetpos(FILE*, fpos_t*); | 
|  | 193 | int fsetpos(FILE*, const fpos_t*); | 
|  | 194 | int fseeko(FILE*, off_t, int); | 
|  | 195 | off_t ftello(FILE*); | 
| Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 196 | #  if defined(__USE_BSD) | 
|  | 197 | FILE* funopen(const void*, | 
|  | 198 | int (*)(void*, char*, int), | 
|  | 199 | int (*)(void*, const char*, int), | 
|  | 200 | fpos_t (*)(void*, fpos_t, int), | 
|  | 201 | int (*)(void*)); | 
|  | 202 | #  endif | 
| Elliott Hughes | 68dc20d | 2015-02-06 22:28:49 -0800 | [diff] [blame] | 203 | #endif | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 204 | int fgetpos64(FILE*, fpos64_t*) __INTRODUCED_IN(24); | 
|  | 205 | int fsetpos64(FILE*, const fpos64_t*) __INTRODUCED_IN(24); | 
|  | 206 | int fseeko64(FILE*, off64_t, int) __INTRODUCED_IN(24); | 
|  | 207 | off64_t ftello64(FILE*) __INTRODUCED_IN(24); | 
| Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 208 | #if defined(__USE_BSD) | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 209 | FILE* funopen64(const void*, int (*)(void*, char*, int), int (*)(void*, const char*, int), | 
|  | 210 | fpos64_t (*)(void*, fpos64_t, int), int (*)(void*)) __INTRODUCED_IN(24); | 
| Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 211 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 212 |  | 
| Elliott Hughes | f226ee5 | 2016-02-03 11:24:28 -0800 | [diff] [blame] | 213 | FILE* fopen(const char* __restrict, const char* __restrict); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 214 | FILE* fopen64(const char* __restrict, const char* __restrict) __INTRODUCED_IN(24); | 
| Elliott Hughes | f226ee5 | 2016-02-03 11:24:28 -0800 | [diff] [blame] | 215 | FILE* freopen(const char* __restrict, const char* __restrict, FILE* __restrict); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 216 | FILE* freopen64(const char* __restrict, const char* __restrict, FILE* __restrict) | 
|  | 217 | __INTRODUCED_IN(24); | 
| Elliott Hughes | f226ee5 | 2016-02-03 11:24:28 -0800 | [diff] [blame] | 218 | FILE* tmpfile(void); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 219 | FILE* tmpfile64(void) __INTRODUCED_IN(24); | 
| Elliott Hughes | f226ee5 | 2016-02-03 11:24:28 -0800 | [diff] [blame] | 220 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 221 | int snprintf(char* __restrict, size_t, const char* __restrict _Nonnull, ...) | 
|  | 222 | __printflike(3, 4) __overloadable __RENAME_CLANG(snprintf); | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 223 | int vfscanf(FILE* __restrict, const char* __restrict _Nonnull, __va_list) __scanflike(2, 0); | 
|  | 224 | int vscanf(const char* _Nonnull , __va_list) __scanflike(1, 0); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 225 | int vsnprintf(char* __restrict, size_t, const char* __restrict _Nonnull, __va_list) | 
|  | 226 | __printflike(3, 0) __overloadable __RENAME_CLANG(vsnprintf); | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 227 | 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] | 228 |  | 
| Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 229 | #define L_ctermid 1024 /* size for ctermid() */ | 
| Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 230 | char* ctermid(char*) __INTRODUCED_IN(26); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 231 |  | 
| Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 232 | FILE* fdopen(int, const char*); | 
|  | 233 | int fileno(FILE*); | 
|  | 234 | int pclose(FILE*); | 
|  | 235 | FILE* popen(const char*, const char*); | 
|  | 236 | void flockfile(FILE*); | 
|  | 237 | int ftrylockfile(FILE*); | 
|  | 238 | void funlockfile(FILE*); | 
|  | 239 | int getc_unlocked(FILE*); | 
|  | 240 | int getchar_unlocked(void); | 
|  | 241 | int putc_unlocked(int, FILE*); | 
|  | 242 | int putchar_unlocked(int); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 243 |  | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 244 | FILE* fmemopen(void*, size_t, const char*) __INTRODUCED_IN(23); | 
|  | 245 | FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 246 |  | 
| Elliott Hughes | 9c8d711 | 2016-06-13 13:23:42 -0700 | [diff] [blame] | 247 | #if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */ | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 248 | int  asprintf(char** __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3); | 
| Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 249 | char* fgetln(FILE* __restrict, size_t* __restrict); | 
|  | 250 | int fpurge(FILE*); | 
|  | 251 | void setbuffer(FILE*, char*, int); | 
|  | 252 | int setlinebuf(FILE*); | 
| Elliott Hughes | 9eb3ae1 | 2016-06-30 09:12:40 -0700 | [diff] [blame] | 253 | 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] | 254 | void clearerr_unlocked(FILE*) __INTRODUCED_IN(23); | 
|  | 255 | int feof_unlocked(FILE*) __INTRODUCED_IN(23); | 
|  | 256 | int ferror_unlocked(FILE*) __INTRODUCED_IN(23); | 
|  | 257 | int fileno_unlocked(FILE*) __INTRODUCED_IN(24); | 
| Elliott Hughes | 03e65eb | 2016-01-26 14:13:04 -0800 | [diff] [blame] | 258 | #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) | 
|  | 259 | #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) | 
| Elliott Hughes | 3ba55f8 | 2016-06-08 18:11:23 -0700 | [diff] [blame] | 260 | #endif /* __USE_BSD */ | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 261 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 262 | char* __fgets_chk(char*, int, FILE*, size_t) __INTRODUCED_IN(17); | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 263 | size_t __fread_chk(void* __restrict, size_t, size_t, FILE* __restrict, size_t) | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 264 | __INTRODUCED_IN(24); | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 265 | size_t __fwrite_chk(const void* __restrict, size_t, size_t, FILE* __restrict, size_t) | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 266 | __INTRODUCED_IN(24); | 
| Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 267 |  | 
| Elliott Hughes | 53cf348 | 2016-08-09 13:06:41 -0700 | [diff] [blame] | 268 | #if defined(__BIONIC_FORTIFY) && !defined(__BIONIC_NO_STDIO_FORTIFY) | 
| Elliott Hughes | ce45fea | 2012-10-22 16:10:27 -0700 | [diff] [blame] | 269 |  | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 270 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 271 | __BIONIC_FORTIFY_INLINE __printflike(3, 0) | 
|  | 272 | int vsnprintf(char *const __pass_object_size dest, size_t size, | 
|  | 273 | const char *_Nonnull format, __va_list ap) __overloadable { | 
| 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 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 277 | __BIONIC_FORTIFY_INLINE __printflike(2, 0) | 
|  | 278 | int vsprintf(char *const __pass_object_size dest, const char *_Nonnull format, | 
|  | 279 | __va_list ap) __overloadable { | 
| Nick Kralevich | 9020fd5 | 2013-04-30 11:31:35 -0700 | [diff] [blame] | 280 | return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap); | 
| Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 281 | } | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 282 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ | 
| Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 283 |  | 
| Nick Kralevich | 621b19d | 2013-06-25 10:02:35 -0700 | [diff] [blame] | 284 | #if defined(__clang__) | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 285 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ | 
|  | 286 | /* | 
|  | 287 | * Simple case: `format` can't have format specifiers, so we can just compare | 
|  | 288 | * its length to the length of `dest` | 
|  | 289 | */ | 
|  | 290 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
|  | 291 | int snprintf(char *__restrict dest, size_t size, const char *__restrict format) | 
|  | 292 | __overloadable | 
|  | 293 | __enable_if(__bos(dest) != __BIONIC_FORTIFY_UNKNOWN_SIZE && | 
|  | 294 | __bos(dest) < __builtin_strlen(format), | 
|  | 295 | "format string will always overflow destination buffer") | 
|  | 296 | __errorattr("format string will always overflow destination buffer"); | 
| Nick Kralevich | 9b549c3 | 2012-06-12 15:59:04 -0700 | [diff] [blame] | 297 |  | 
|  | 298 | __BIONIC_FORTIFY_INLINE | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 299 | __printflike(3, 4) | 
|  | 300 | int snprintf(char *__restrict const __pass_object_size dest, | 
|  | 301 | size_t size, const char *__restrict format, ...) __overloadable { | 
|  | 302 | va_list va; | 
|  | 303 | va_start(va, format); | 
|  | 304 | int result = __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, va); | 
|  | 305 | va_end(va); | 
|  | 306 | return result; | 
| Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 307 | } | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 308 |  | 
|  | 309 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
|  | 310 | int sprintf(char *__restrict dest, const char *__restrict format) __overloadable | 
|  | 311 | __enable_if(__bos(dest) != __BIONIC_FORTIFY_UNKNOWN_SIZE && | 
|  | 312 | __bos(dest) < __builtin_strlen(format), | 
|  | 313 | "format string will always overflow destination buffer") | 
|  | 314 | __errorattr("format string will always overflow destination buffer"); | 
|  | 315 |  | 
|  | 316 | __BIONIC_FORTIFY_INLINE | 
|  | 317 | __printflike(2, 3) | 
|  | 318 | int sprintf(char *__restrict const __pass_object_size dest, | 
|  | 319 | const char *__restrict format, ...) __overloadable { | 
|  | 320 | va_list va; | 
|  | 321 | va_start(va, format); | 
|  | 322 | int result = __builtin___vsprintf_chk(dest, 0, __bos(dest), format, va); | 
|  | 323 | va_end(va); | 
|  | 324 | return result; | 
|  | 325 | } | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 326 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ | 
| Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 327 |  | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 328 | #if __ANDROID_API__ >= __ANDROID_API_N__ | 
| Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 329 | __BIONIC_FORTIFY_INLINE | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 330 | size_t fread(void *__restrict buf, size_t size, size_t count, | 
|  | 331 | FILE *__restrict stream) __overloadable | 
|  | 332 | __enable_if(__unsafe_check_mul_overflow(size, count), "size * count overflows") | 
|  | 333 | __errorattr("size * count overflows"); | 
|  | 334 |  | 
|  | 335 | __BIONIC_FORTIFY_INLINE | 
|  | 336 | size_t fread(void *__restrict buf, size_t size, size_t count, | 
|  | 337 | FILE *__restrict stream) __overloadable | 
|  | 338 | __enable_if(!__unsafe_check_mul_overflow(size, count), "no overflow") | 
|  | 339 | __enable_if(__bos(buf) != __BIONIC_FORTIFY_UNKNOWN_SIZE && | 
|  | 340 | size * count > __bos(buf), "size * count is too large") | 
|  | 341 | __errorattr("size * count is too large"); | 
|  | 342 |  | 
|  | 343 | __BIONIC_FORTIFY_INLINE | 
| George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 344 | size_t fread(void *__restrict const __pass_object_size0 buf, size_t size, | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 345 | size_t count, FILE *__restrict stream) __overloadable { | 
| Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 346 | size_t bos = __bos0(buf); | 
|  | 347 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 348 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
|  | 349 | return __call_bypassing_fortify(fread)(buf, size, count, stream); | 
|  | 350 | } | 
|  | 351 |  | 
|  | 352 | return __fread_chk(buf, size, count, stream, bos); | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | size_t fwrite(const void * __restrict buf, size_t size, | 
|  | 356 | size_t count, FILE * __restrict stream) __overloadable | 
|  | 357 | __enable_if(__unsafe_check_mul_overflow(size, count), | 
|  | 358 | "size * count overflows") | 
|  | 359 | __errorattr("size * count overflows"); | 
|  | 360 |  | 
|  | 361 | size_t fwrite(const void * __restrict buf, size_t size, | 
|  | 362 | size_t count, FILE * __restrict stream) __overloadable | 
|  | 363 | __enable_if(!__unsafe_check_mul_overflow(size, count), "no overflow") | 
|  | 364 | __enable_if(__bos(buf) != __BIONIC_FORTIFY_UNKNOWN_SIZE && | 
|  | 365 | size * count > __bos(buf), "size * count is too large") | 
|  | 366 | __errorattr("size * count is too large"); | 
|  | 367 |  | 
|  | 368 | __BIONIC_FORTIFY_INLINE | 
| George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 369 | size_t fwrite(const void * __restrict const __pass_object_size0 buf, | 
|  | 370 | size_t size, size_t count, FILE * __restrict stream) | 
|  | 371 | __overloadable { | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 372 | size_t bos = __bos0(buf); | 
|  | 373 |  | 
|  | 374 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
|  | 375 | return __call_bypassing_fortify(fwrite)(buf, size, count, stream); | 
|  | 376 | } | 
|  | 377 |  | 
|  | 378 | return __fwrite_chk(buf, size, count, stream, bos); | 
|  | 379 | } | 
|  | 380 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ | 
|  | 381 |  | 
| Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 382 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 383 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
|  | 384 | char *fgets(char* __restrict dest, int size, FILE* stream) __overloadable | 
|  | 385 | __enable_if(size < 0, "size is negative") | 
|  | 386 | __errorattr("size is negative"); | 
|  | 387 |  | 
|  | 388 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
|  | 389 | char *fgets(char* dest, int size, FILE* stream) __overloadable | 
|  | 390 | __enable_if(size >= 0 && size > __bos(dest), | 
|  | 391 | "size is larger than the destination buffer") | 
|  | 392 | __errorattr("size is larger than the destination buffer"); | 
|  | 393 |  | 
|  | 394 | __BIONIC_FORTIFY_INLINE | 
|  | 395 | char *fgets(char* __restrict const __pass_object_size dest, | 
|  | 396 | int size, FILE* stream) __overloadable { | 
|  | 397 | size_t bos = __bos(dest); | 
|  | 398 |  | 
|  | 399 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
|  | 400 | return __call_bypassing_fortify(fgets)(dest, size, stream); | 
|  | 401 | } | 
|  | 402 |  | 
|  | 403 | return __fgets_chk(dest, size, stream, bos); | 
|  | 404 | } | 
| Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 405 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 406 |  | 
|  | 407 | #else /* defined(__clang__) */ | 
|  | 408 |  | 
|  | 409 | size_t __fread_real(void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fread); | 
|  | 410 | __errordecl(__fread_too_big_error, "fread called with size * count bigger than buffer"); | 
|  | 411 | __errordecl(__fread_overflow, "fread called with overflowing size * count"); | 
|  | 412 |  | 
|  | 413 | char* __fgets_real(char*, int, FILE*) __RENAME(fgets); | 
|  | 414 | __errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer"); | 
|  | 415 | __errordecl(__fgets_too_small_error, "fgets called with size less than zero"); | 
|  | 416 |  | 
|  | 417 | size_t __fwrite_real(const void * __restrict, size_t, size_t, FILE * __restrict) __RENAME(fwrite); | 
|  | 418 | __errordecl(__fwrite_too_big_error, "fwrite called with size * count bigger than buffer"); | 
|  | 419 | __errordecl(__fwrite_overflow, "fwrite called with overflowing size * count"); | 
|  | 420 |  | 
|  | 421 |  | 
|  | 422 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ | 
|  | 423 | __BIONIC_FORTIFY_INLINE __printflike(3, 4) | 
|  | 424 | int snprintf(char *__restrict dest, size_t size, const char* _Nonnull format, ...) | 
|  | 425 | { | 
|  | 426 | return __builtin___snprintf_chk(dest, size, 0, __bos(dest), format, | 
|  | 427 | __builtin_va_arg_pack()); | 
|  | 428 | } | 
|  | 429 |  | 
|  | 430 | __BIONIC_FORTIFY_INLINE __printflike(2, 3) | 
|  | 431 | int sprintf(char *__restrict dest, const char* _Nonnull format, ...) { | 
|  | 432 | return __builtin___sprintf_chk(dest, 0, __bos(dest), format, | 
|  | 433 | __builtin_va_arg_pack()); | 
|  | 434 | } | 
|  | 435 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ | 
|  | 436 |  | 
|  | 437 | #if __ANDROID_API__ >= __ANDROID_API_N__ | 
|  | 438 | __BIONIC_FORTIFY_INLINE | 
|  | 439 | size_t fread(void *__restrict buf, size_t size, size_t count, FILE * __restrict stream) { | 
|  | 440 | size_t bos = __bos0(buf); | 
|  | 441 |  | 
| Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 442 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
|  | 443 | return __fread_real(buf, size, count, stream); | 
|  | 444 | } | 
|  | 445 |  | 
|  | 446 | if (__builtin_constant_p(size) && __builtin_constant_p(count)) { | 
|  | 447 | size_t total; | 
|  | 448 | if (__size_mul_overflow(size, count, &total)) { | 
|  | 449 | __fread_overflow(); | 
|  | 450 | } | 
|  | 451 |  | 
|  | 452 | if (total > bos) { | 
|  | 453 | __fread_too_big_error(); | 
|  | 454 | } | 
|  | 455 |  | 
|  | 456 | return __fread_real(buf, size, count, stream); | 
|  | 457 | } | 
| Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 458 |  | 
|  | 459 | return __fread_chk(buf, size, count, stream, bos); | 
|  | 460 | } | 
|  | 461 |  | 
|  | 462 | __BIONIC_FORTIFY_INLINE | 
|  | 463 | size_t fwrite(const void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) { | 
|  | 464 | size_t bos = __bos0(buf); | 
|  | 465 |  | 
| Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 466 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
|  | 467 | return __fwrite_real(buf, size, count, stream); | 
|  | 468 | } | 
|  | 469 |  | 
|  | 470 | if (__builtin_constant_p(size) && __builtin_constant_p(count)) { | 
|  | 471 | size_t total; | 
|  | 472 | if (__size_mul_overflow(size, count, &total)) { | 
|  | 473 | __fwrite_overflow(); | 
|  | 474 | } | 
|  | 475 |  | 
|  | 476 | if (total > bos) { | 
|  | 477 | __fwrite_too_big_error(); | 
|  | 478 | } | 
|  | 479 |  | 
|  | 480 | return __fwrite_real(buf, size, count, stream); | 
|  | 481 | } | 
| Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 482 |  | 
|  | 483 | return __fwrite_chk(buf, size, count, stream, bos); | 
|  | 484 | } | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 485 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ | 
| Daniel Micay | fed2659 | 2015-07-18 13:55:51 -0400 | [diff] [blame] | 486 |  | 
| Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 487 | #if __ANDROID_API__ >= __ANDROID_API_J_MR1__ | 
| Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 488 | __BIONIC_FORTIFY_INLINE | 
| Elliott Hughes | cd0609f | 2013-12-19 12:21:07 -0800 | [diff] [blame] | 489 | char *fgets(char* dest, int size, FILE* stream) { | 
| Nick Kralevich | 9020fd5 | 2013-04-30 11:31:35 -0700 | [diff] [blame] | 490 | size_t bos = __bos(dest); | 
| Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 491 |  | 
|  | 492 | // Compiler can prove, at compile time, that the passed in size | 
|  | 493 | // is always negative. Force a compiler error. | 
|  | 494 | if (__builtin_constant_p(size) && (size < 0)) { | 
|  | 495 | __fgets_too_small_error(); | 
|  | 496 | } | 
|  | 497 |  | 
|  | 498 | // Compiler doesn't know destination size. Don't call __fgets_chk | 
| Nick Kralevich | 9b6cc22 | 2012-07-13 14:46:36 -0700 | [diff] [blame] | 499 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
| Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 500 | return __fgets_real(dest, size, stream); | 
|  | 501 | } | 
|  | 502 |  | 
|  | 503 | // Compiler can prove, at compile time, that the passed in size | 
|  | 504 | // is always <= the actual object size. Don't call __fgets_chk | 
| Elliott Hughes | 41b3179 | 2013-01-28 10:36:31 -0800 | [diff] [blame] | 505 | if (__builtin_constant_p(size) && (size <= (int) bos)) { | 
| Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 506 | return __fgets_real(dest, size, stream); | 
|  | 507 | } | 
|  | 508 |  | 
|  | 509 | // Compiler can prove, at compile time, that the passed in size | 
|  | 510 | // is always > the actual object size. Force a compiler error. | 
| Elliott Hughes | 41b3179 | 2013-01-28 10:36:31 -0800 | [diff] [blame] | 511 | if (__builtin_constant_p(size) && (size > (int) bos)) { | 
| Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 512 | __fgets_too_big_error(); | 
|  | 513 | } | 
|  | 514 |  | 
|  | 515 | return __fgets_chk(dest, size, stream, bos); | 
|  | 516 | } | 
| Dan Albert | 9c2094f | 2017-02-14 19:28:18 -0800 | [diff] [blame] | 517 | #endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ | 
| Nick Kralevich | 965dbc6 | 2012-07-03 11:45:31 -0700 | [diff] [blame] | 518 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 519 | #endif /* defined(__clang__) */ | 
| Nick Kralevich | c6eb985 | 2013-06-24 11:44:00 -0700 | [diff] [blame] | 520 | #endif /* defined(__BIONIC_FORTIFY) */ | 
| Nick Kralevich | cffdf66 | 2012-06-11 15:50:57 -0700 | [diff] [blame] | 521 |  | 
| Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 522 | #if defined(__clang__) | 
|  | 523 | #pragma clang diagnostic pop | 
|  | 524 | #endif | 
|  | 525 |  | 
| Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 526 | __END_DECLS | 
|  | 527 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 528 | #endif /* _STDIO_H_ */ |