blob: 8fefba585f04d7fffd54932da03126d1ee06c5f9 [file] [log] [blame]
Ben Cheng7823f2a2014-04-08 14:53:42 -07001/* DO NOT EDIT THIS FILE.
2
3 It has been auto-edited by fixincludes from:
4
Rong Xua1f277f2014-09-05 13:42:16 -07005 "/tmp/ndk-xur/build/toolchain/prefix/sysroot/usr/include/stdio.h"
Ben Cheng7823f2a2014-04-08 14:53:42 -07006
7 This had to be done to correct non-standard usages in the
8 original, manufacturer supplied header file. */
9
10/* $OpenBSD: stdio.h,v 1.35 2006/01/13 18:10:09 miod Exp $ */
11/* $NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $ */
12
13/*-
14 * Copyright (c) 1990 The Regents of the University of California.
15 * All rights reserved.
16 *
17 * This code is derived from software contributed to Berkeley by
18 * Chris Torek.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * 3. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)stdio.h 5.17 (Berkeley) 6/3/91
45 */
46
47#ifndef _STDIO_H_
48#define _STDIO_H_
49
50#include <sys/cdefs.h>
51#include <sys/types.h>
52
53#include <stdarg.h>
54#include <stddef.h>
55
56#define __need_NULL
57#include <stddef.h>
58
59#define _FSTDIO /* Define for new stdio with functions. */
60
61typedef off_t fpos_t; /* stdio file position type */
62
63/*
64 * NB: to fit things in six character monocase externals, the stdio
65 * code uses the prefix `__s' for stdio objects, typically followed
66 * by a three-character attempt at a mnemonic.
67 */
68
69/* stdio buffers */
Rong Xua1f277f2014-09-05 13:42:16 -070070#if defined(__LP64__)
71struct __sbuf {
72 unsigned char* _base;
73 size_t _size;
74};
75#else
Ben Cheng7823f2a2014-04-08 14:53:42 -070076struct __sbuf {
77 unsigned char *_base;
78 int _size;
79};
Rong Xua1f277f2014-09-05 13:42:16 -070080#endif
Ben Cheng7823f2a2014-04-08 14:53:42 -070081
82/*
83 * stdio state variables.
84 *
85 * The following always hold:
86 *
87 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
88 * _lbfsize is -_bf._size, else _lbfsize is 0
89 * if _flags&__SRD, _w is 0
90 * if _flags&__SWR, _r is 0
91 *
92 * This ensures that the getc and putc macros (or inline functions) never
93 * try to write or read from a file that is in `read' or `write' mode.
94 * (Moreover, they can, and do, automatically switch from read mode to
95 * write mode, and back, on "r+" and "w+" files.)
96 *
97 * _lbfsize is used only to make the inline line-buffered output stream
98 * code as compact as possible.
99 *
100 * _ub, _up, and _ur are used when ungetc() pushes back more characters
101 * than fit in the current _bf, or when ungetc() pushes back a character
102 * that does not match the previous one in _bf. When this happens,
103 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
104 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
105 *
106 * NOTE: if you change this structure, you also need to update the
107 * std() initializer in findfp.c.
108 */
109typedef struct __sFILE {
110 unsigned char *_p; /* current position in (some) buffer */
111 int _r; /* read space left for getc() */
112 int _w; /* write space left for putc() */
Rong Xua1f277f2014-09-05 13:42:16 -0700113#if defined(__LP64__)
114 int _flags; /* flags, below; this FILE is free if 0 */
115 int _file; /* fileno, if Unix descriptor, else -1 */
116#else
Ben Cheng7823f2a2014-04-08 14:53:42 -0700117 short _flags; /* flags, below; this FILE is free if 0 */
118 short _file; /* fileno, if Unix descriptor, else -1 */
Rong Xua1f277f2014-09-05 13:42:16 -0700119#endif
Ben Cheng7823f2a2014-04-08 14:53:42 -0700120 struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
121 int _lbfsize; /* 0 or -_bf._size, for inline putc */
122
123 /* operations */
124 void *_cookie; /* cookie passed to io functions */
125 int (*_close)(void *);
126 int (*_read)(void *, char *, int);
127 fpos_t (*_seek)(void *, fpos_t, int);
128 int (*_write)(void *, const char *, int);
129
130 /* extension data, to avoid further ABI breakage */
131 struct __sbuf _ext;
132 /* data for long sequences of ungetc() */
133 unsigned char *_up; /* saved _p when _p is doing ungetc data */
134 int _ur; /* saved _r when _r is counting ungetc data */
135
136 /* tricks to meet minimum requirements even when malloc() fails */
137 unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
138 unsigned char _nbuf[1]; /* guarantee a getc() buffer */
139
140 /* separate buffer for fgetln() when line crosses buffer boundary */
141 struct __sbuf _lb; /* buffer for fgetln() */
142
143 /* Unix stdio files get aligned to block boundaries on fseek() */
144 int _blksize; /* stat.st_blksize (may be != _bf._size) */
145 fpos_t _offset; /* current lseek offset */
146} FILE;
147
148__BEGIN_DECLS
149extern FILE __sF[];
150__END_DECLS
151
152#define __SLBF 0x0001 /* line buffered */
153#define __SNBF 0x0002 /* unbuffered */
154#define __SRD 0x0004 /* OK to read */
155#define __SWR 0x0008 /* OK to write */
156 /* RD and WR are never simultaneously asserted */
157#define __SRW 0x0010 /* open for reading & writing */
158#define __SEOF 0x0020 /* found EOF */
159#define __SERR 0x0040 /* found error */
160#define __SMBF 0x0080 /* _buf is from malloc */
161#define __SAPP 0x0100 /* fdopen()ed in append mode */
162#define __SSTR 0x0200 /* this is an sprintf/snprintf string */
163#define __SOPT 0x0400 /* do fseek() optimization */
164#define __SNPT 0x0800 /* do not do fseek() optimization */
165#define __SOFF 0x1000 /* set iff _offset is in fact correct */
166#define __SMOD 0x2000 /* true => fgetln modified _p text */
167#define __SALC 0x4000 /* allocate string space dynamically */
168#define __SIGN 0x8000 /* ignore this file in _fwalk */
169
170/*
171 * The following three definitions are for ANSI C, which took them
172 * from System V, which brilliantly took internal interface macros and
173 * made them official arguments to setvbuf(), without renaming them.
174 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
175 *
176 * Although numbered as their counterparts above, the implementation
177 * does not rely on this.
178 */
179#define _IOFBF 0 /* setvbuf should set fully buffered */
180#define _IOLBF 1 /* setvbuf should set line buffered */
181#define _IONBF 2 /* setvbuf should set unbuffered */
182
183#define BUFSIZ 1024 /* size of buffer used by setbuf */
184#define EOF (-1)
185
186/*
187 * FOPEN_MAX is a minimum maximum, and is the number of streams that
188 * stdio can provide without attempting to allocate further resources
189 * (which could fail). Do not use this for anything.
190 */
191
192#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
193#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
194
195/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
196#if __BSD_VISIBLE || __XPG_VISIBLE
197#define P_tmpdir "/tmp/"
198#endif
199#define L_tmpnam 1024 /* XXX must be == PATH_MAX */
200#define TMP_MAX 308915776
201
202/* Always ensure that these are consistent with <fcntl.h> and <unistd.h>! */
203#ifndef SEEK_SET
204#define SEEK_SET 0 /* set file offset to offset */
205#endif
206#ifndef SEEK_CUR
207#define SEEK_CUR 1 /* set file offset to current plus offset */
208#endif
209#ifndef SEEK_END
210#define SEEK_END 2 /* set file offset to EOF plus offset */
211#endif
212
213#define stdin (&__sF[0])
214#define stdout (&__sF[1])
215#define stderr (&__sF[2])
216
217/*
218 * Functions defined in ANSI C standard.
219 */
220__BEGIN_DECLS
221void clearerr(FILE *);
222int fclose(FILE *);
223int feof(FILE *);
224int ferror(FILE *);
225int fflush(FILE *);
226int fgetc(FILE *);
227char *fgets(char * __restrict, int, FILE * __restrict);
228FILE *fopen(const char * __restrict , const char * __restrict);
229int fprintf(FILE * __restrict , const char * __restrict, ...)
230 __printflike(2, 3);
231int fputc(int, FILE *);
232int fputs(const char * __restrict, FILE * __restrict);
233size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
234FILE *freopen(const char * __restrict, const char * __restrict,
235 FILE * __restrict);
236int fscanf(FILE * __restrict, const char * __restrict, ...)
237 __scanflike(2, 3);
238int fseek(FILE *, long, int);
239long ftell(FILE *);
240size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
241int getc(FILE *);
242int getchar(void);
243ssize_t getdelim(char ** __restrict, size_t * __restrict, int,
244 FILE * __restrict);
245ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict);
246
Ben Cheng7823f2a2014-04-08 14:53:42 -0700247void perror(const char *);
248int printf(const char * __restrict, ...)
249 __printflike(1, 2);
250int putc(int, FILE *);
251int putchar(int);
252int puts(const char *);
253int remove(const char *);
254void rewind(FILE *);
255int scanf(const char * __restrict, ...)
256 __scanflike(1, 2);
257void setbuf(FILE * __restrict, char * __restrict);
258int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
259int sscanf(const char * __restrict, const char * __restrict, ...)
260 __scanflike(2, 3);
261FILE *tmpfile(void);
262int ungetc(int, FILE *);
263int vfprintf(FILE * __restrict, const char * __restrict, __gnuc_va_list)
264 __printflike(2, 0);
265int vprintf(const char * __restrict, __gnuc_va_list)
266 __printflike(1, 0);
267
Rong Xua1f277f2014-09-05 13:42:16 -0700268int dprintf(int, const char * __restrict, ...) __printflike(2, 3);
269int vdprintf(int, const char * __restrict, __gnuc_va_list) __printflike(2, 0);
270
Ben Cheng7823f2a2014-04-08 14:53:42 -0700271#ifndef __AUDIT__
Rong Xua1f277f2014-09-05 13:42:16 -0700272#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
Ben Cheng7823f2a2014-04-08 14:53:42 -0700273char* gets(char*) __warnattr("gets is very unsafe; consider using fgets");
Rong Xua1f277f2014-09-05 13:42:16 -0700274#endif
Ben Cheng7823f2a2014-04-08 14:53:42 -0700275int sprintf(char* __restrict, const char* __restrict, ...)
276 __printflike(2, 3); //__warnattr("sprintf is often misused; please use snprintf");
277char* tmpnam(char*) __warnattr("tmpnam possibly used unsafely; consider using mkstemp");
278int vsprintf(char* __restrict, const char* __restrict, __gnuc_va_list)
279 __printflike(2, 0); //__warnattr("vsprintf is often misused; please use vsnprintf");
280#if __XPG_VISIBLE
281char* tempnam(const char*, const char*)
282 __warnattr("tempnam possibly used unsafely; consider using mkstemp");
283#endif
284#endif
285
286extern int rename(const char*, const char*);
287extern int renameat(int, const char*, int, const char*);
288
289int fgetpos(FILE * __restrict, fpos_t * __restrict);
290int fsetpos(FILE *, const fpos_t *);
291
292int fseeko(FILE *, off_t, int);
293off_t ftello(FILE *);
294
295#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE
296int snprintf(char * __restrict, size_t, const char * __restrict, ...)
297 __printflike(3, 4);
298int vfscanf(FILE * __restrict, const char * __restrict, __gnuc_va_list)
299 __scanflike(2, 0);
300int vscanf(const char *, __gnuc_va_list)
301 __scanflike(1, 0);
302int vsnprintf(char * __restrict, size_t, const char * __restrict, __gnuc_va_list)
303 __printflike(3, 0);
304int vsscanf(const char * __restrict, const char * __restrict, __gnuc_va_list)
305 __scanflike(2, 0);
306#endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */
307
308__END_DECLS
309
310
311/*
312 * Functions defined in POSIX 1003.1.
313 */
314#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
315#define L_ctermid 1024 /* size for ctermid(); PATH_MAX */
Ben Cheng7823f2a2014-04-08 14:53:42 -0700316
317__BEGIN_DECLS
Ben Cheng7823f2a2014-04-08 14:53:42 -0700318FILE *fdopen(int, const char *);
319int fileno(FILE *);
320
321#if (__POSIX_VISIBLE >= 199209)
322int pclose(FILE *);
323FILE *popen(const char *, const char *);
324#endif
325
326#if __POSIX_VISIBLE >= 199506
327void flockfile(FILE *);
328int ftrylockfile(FILE *);
329void funlockfile(FILE *);
330
331/*
332 * These are normally used through macros as defined below, but POSIX
333 * requires functions as well.
334 */
335int getc_unlocked(FILE *);
336int getchar_unlocked(void);
337int putc_unlocked(int, FILE *);
338int putchar_unlocked(int);
339#endif /* __POSIX_VISIBLE >= 199506 */
340
341__END_DECLS
342
343#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
344
345/*
346 * Routines that are purely local.
347 */
348#if __BSD_VISIBLE
349__BEGIN_DECLS
350int asprintf(char ** __restrict, const char * __restrict, ...)
351 __printflike(2, 3);
352char *fgetln(FILE * __restrict, size_t * __restrict);
353int fpurge(FILE *);
Ben Cheng7823f2a2014-04-08 14:53:42 -0700354void setbuffer(FILE *, char *, int);
355int setlinebuf(FILE *);
356int vasprintf(char ** __restrict, const char * __restrict,
357 __gnuc_va_list)
358 __printflike(2, 0);
359__END_DECLS
360
361/*
362 * Stdio function-access interface.
363 */
364__BEGIN_DECLS
365FILE *funopen(const void *,
366 int (*)(void *, char *, int),
367 int (*)(void *, const char *, int),
368 fpos_t (*)(void *, fpos_t, int),
369 int (*)(void *));
370__END_DECLS
371#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
372#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
373#endif /* __BSD_VISIBLE */
374
Ben Cheng7823f2a2014-04-08 14:53:42 -0700375#if defined(__BIONIC_FORTIFY)
376
377__BEGIN_DECLS
378
379__BIONIC_FORTIFY_INLINE
380__printflike(3, 0)
381int vsnprintf(char *dest, size_t size, const char *format, __va_list ap)
382{
383 return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
384}
385
386__BIONIC_FORTIFY_INLINE
387__printflike(2, 0)
388int vsprintf(char *dest, const char *format, __va_list ap)
389{
390 return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap);
391}
392
393#if defined(__clang__)
Ben Cheng79781f52014-05-19 10:33:46 -0700394 #if !defined(snprintf)
395 #define __wrap_snprintf(dest, size, ...) __builtin___snprintf_chk(dest, size, 0, __bos(dest), __VA_ARGS__)
396 #define snprintf(...) __wrap_snprintf(__VA_ARGS__)
397 #endif
Ben Cheng7823f2a2014-04-08 14:53:42 -0700398#else
399__BIONIC_FORTIFY_INLINE
400__printflike(3, 4)
401int snprintf(char *dest, size_t size, const char *format, ...)
402{
403 return __builtin___snprintf_chk(dest, size, 0,
404 __bos(dest), format, __builtin_va_arg_pack());
405}
406#endif
407
408#if defined(__clang__)
Ben Cheng79781f52014-05-19 10:33:46 -0700409 #if !defined(sprintf)
410 #define __wrap_sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__)
411 #define sprintf(...) __wrap_sprintf(__VA_ARGS__)
412 #endif
Ben Cheng7823f2a2014-04-08 14:53:42 -0700413#else
414__BIONIC_FORTIFY_INLINE
415__printflike(2, 3)
416int sprintf(char *dest, const char *format, ...)
417{
418 return __builtin___sprintf_chk(dest, 0,
419 __bos(dest), format, __builtin_va_arg_pack());
420}
421#endif
422
423extern char* __fgets_chk(char*, int, FILE*, size_t);
424extern char* __fgets_real(char*, int, FILE*) __asm__(__USER_LABEL_PREFIX__ "fgets");
425__errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
426__errordecl(__fgets_too_small_error, "fgets called with size less than zero");
427
428#if !defined(__clang__)
429
430__BIONIC_FORTIFY_INLINE
431char *fgets(char* dest, int size, FILE* stream) {
432 size_t bos = __bos(dest);
433
434 // Compiler can prove, at compile time, that the passed in size
435 // is always negative. Force a compiler error.
436 if (__builtin_constant_p(size) && (size < 0)) {
437 __fgets_too_small_error();
438 }
439
440 // Compiler doesn't know destination size. Don't call __fgets_chk
441 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
442 return __fgets_real(dest, size, stream);
443 }
444
445 // Compiler can prove, at compile time, that the passed in size
446 // is always <= the actual object size. Don't call __fgets_chk
447 if (__builtin_constant_p(size) && (size <= (int) bos)) {
448 return __fgets_real(dest, size, stream);
449 }
450
451 // Compiler can prove, at compile time, that the passed in size
452 // is always > the actual object size. Force a compiler error.
453 if (__builtin_constant_p(size) && (size > (int) bos)) {
454 __fgets_too_big_error();
455 }
456
457 return __fgets_chk(dest, size, stream, bos);
458}
459
460#endif /* !defined(__clang__) */
461
462__END_DECLS
463
464#endif /* defined(__BIONIC_FORTIFY) */
465
466#endif /* _STDIO_H_ */