blob: a5c846efcd1d9236f2582f5f7784a6c7783a0fb1 [file] [log] [blame]
Ben Cheng09ebc132013-10-18 00:02:49 -07001/* DO NOT EDIT THIS FILE.
2
3 It has been auto-edited by fixincludes from:
4
5 "/tmp/toolchain-build-aarch64-linux-4.8/prefix/sysroot/usr/include/stdio.h"
6
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
Ben Cheng09ebc132013-10-18 00:02:49 -070053#include <stdarg.h>
Ben Cheng09ebc132013-10-18 00:02:49 -070054#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 */
70struct __sbuf {
71 unsigned char *_base;
72 int _size;
73};
74
75/*
76 * stdio state variables.
77 *
78 * The following always hold:
79 *
80 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
81 * _lbfsize is -_bf._size, else _lbfsize is 0
82 * if _flags&__SRD, _w is 0
83 * if _flags&__SWR, _r is 0
84 *
85 * This ensures that the getc and putc macros (or inline functions) never
86 * try to write or read from a file that is in `read' or `write' mode.
87 * (Moreover, they can, and do, automatically switch from read mode to
88 * write mode, and back, on "r+" and "w+" files.)
89 *
90 * _lbfsize is used only to make the inline line-buffered output stream
91 * code as compact as possible.
92 *
93 * _ub, _up, and _ur are used when ungetc() pushes back more characters
94 * than fit in the current _bf, or when ungetc() pushes back a character
95 * that does not match the previous one in _bf. When this happens,
96 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
97 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
98 *
99 * NOTE: if you change this structure, you also need to update the
100 * std() initializer in findfp.c.
101 */
102typedef struct __sFILE {
103 unsigned char *_p; /* current position in (some) buffer */
104 int _r; /* read space left for getc() */
105 int _w; /* write space left for putc() */
106 short _flags; /* flags, below; this FILE is free if 0 */
107 short _file; /* fileno, if Unix descriptor, else -1 */
108 struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
109 int _lbfsize; /* 0 or -_bf._size, for inline putc */
110
111 /* operations */
112 void *_cookie; /* cookie passed to io functions */
113 int (*_close)(void *);
114 int (*_read)(void *, char *, int);
115 fpos_t (*_seek)(void *, fpos_t, int);
116 int (*_write)(void *, const char *, int);
117
118 /* extension data, to avoid further ABI breakage */
119 struct __sbuf _ext;
120 /* data for long sequences of ungetc() */
121 unsigned char *_up; /* saved _p when _p is doing ungetc data */
122 int _ur; /* saved _r when _r is counting ungetc data */
123
124 /* tricks to meet minimum requirements even when malloc() fails */
125 unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
126 unsigned char _nbuf[1]; /* guarantee a getc() buffer */
127
128 /* separate buffer for fgetln() when line crosses buffer boundary */
129 struct __sbuf _lb; /* buffer for fgetln() */
130
131 /* Unix stdio files get aligned to block boundaries on fseek() */
132 int _blksize; /* stat.st_blksize (may be != _bf._size) */
133 fpos_t _offset; /* current lseek offset */
134} FILE;
135
136__BEGIN_DECLS
137extern FILE __sF[];
138__END_DECLS
139
140#define __SLBF 0x0001 /* line buffered */
141#define __SNBF 0x0002 /* unbuffered */
142#define __SRD 0x0004 /* OK to read */
143#define __SWR 0x0008 /* OK to write */
144 /* RD and WR are never simultaneously asserted */
145#define __SRW 0x0010 /* open for reading & writing */
146#define __SEOF 0x0020 /* found EOF */
147#define __SERR 0x0040 /* found error */
148#define __SMBF 0x0080 /* _buf is from malloc */
149#define __SAPP 0x0100 /* fdopen()ed in append mode */
150#define __SSTR 0x0200 /* this is an sprintf/snprintf string */
Ben Cheng7334f0a2014-04-30 14:28:17 -0700151#define __SOPT 0x0400 /* do fseek() optimization */
152#define __SNPT 0x0800 /* do not do fseek() optimization */
Ben Cheng09ebc132013-10-18 00:02:49 -0700153#define __SOFF 0x1000 /* set iff _offset is in fact correct */
154#define __SMOD 0x2000 /* true => fgetln modified _p text */
155#define __SALC 0x4000 /* allocate string space dynamically */
Ben Cheng7334f0a2014-04-30 14:28:17 -0700156#define __SIGN 0x8000 /* ignore this file in _fwalk */
Ben Cheng09ebc132013-10-18 00:02:49 -0700157
158/*
159 * The following three definitions are for ANSI C, which took them
160 * from System V, which brilliantly took internal interface macros and
161 * made them official arguments to setvbuf(), without renaming them.
162 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
163 *
164 * Although numbered as their counterparts above, the implementation
165 * does not rely on this.
166 */
167#define _IOFBF 0 /* setvbuf should set fully buffered */
168#define _IOLBF 1 /* setvbuf should set line buffered */
169#define _IONBF 2 /* setvbuf should set unbuffered */
170
171#define BUFSIZ 1024 /* size of buffer used by setbuf */
Ben Cheng09ebc132013-10-18 00:02:49 -0700172#define EOF (-1)
173
174/*
Ben Cheng7334f0a2014-04-30 14:28:17 -0700175 * FOPEN_MAX is a minimum maximum, and is the number of streams that
176 * stdio can provide without attempting to allocate further resources
177 * (which could fail). Do not use this for anything.
Ben Cheng09ebc132013-10-18 00:02:49 -0700178 */
Ben Cheng7334f0a2014-04-30 14:28:17 -0700179
Ben Cheng09ebc132013-10-18 00:02:49 -0700180#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
181#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
182
183/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
184#if __BSD_VISIBLE || __XPG_VISIBLE
185#define P_tmpdir "/tmp/"
186#endif
187#define L_tmpnam 1024 /* XXX must be == PATH_MAX */
188#define TMP_MAX 308915776
189
Ben Cheng7334f0a2014-04-30 14:28:17 -0700190/* Always ensure that these are consistent with <fcntl.h> and <unistd.h>! */
Ben Cheng09ebc132013-10-18 00:02:49 -0700191#ifndef SEEK_SET
192#define SEEK_SET 0 /* set file offset to offset */
193#endif
194#ifndef SEEK_CUR
195#define SEEK_CUR 1 /* set file offset to current plus offset */
196#endif
197#ifndef SEEK_END
198#define SEEK_END 2 /* set file offset to EOF plus offset */
199#endif
200
201#define stdin (&__sF[0])
202#define stdout (&__sF[1])
203#define stderr (&__sF[2])
204
205/*
206 * Functions defined in ANSI C standard.
207 */
208__BEGIN_DECLS
209void clearerr(FILE *);
210int fclose(FILE *);
211int feof(FILE *);
212int ferror(FILE *);
213int fflush(FILE *);
214int fgetc(FILE *);
Ben Cheng7334f0a2014-04-30 14:28:17 -0700215char *fgets(char * __restrict, int, FILE * __restrict);
216FILE *fopen(const char * __restrict , const char * __restrict);
217int fprintf(FILE * __restrict , const char * __restrict, ...)
218 __printflike(2, 3);
Ben Cheng09ebc132013-10-18 00:02:49 -0700219int fputc(int, FILE *);
Ben Cheng7334f0a2014-04-30 14:28:17 -0700220int fputs(const char * __restrict, FILE * __restrict);
221size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
222FILE *freopen(const char * __restrict, const char * __restrict,
223 FILE * __restrict);
224int fscanf(FILE * __restrict, const char * __restrict, ...)
225 __scanflike(2, 3);
Ben Cheng09ebc132013-10-18 00:02:49 -0700226int fseek(FILE *, long, int);
Ben Cheng09ebc132013-10-18 00:02:49 -0700227long ftell(FILE *);
Ben Cheng7334f0a2014-04-30 14:28:17 -0700228size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
Ben Cheng09ebc132013-10-18 00:02:49 -0700229int getc(FILE *);
230int getchar(void);
Ben Cheng7334f0a2014-04-30 14:28:17 -0700231ssize_t getdelim(char ** __restrict, size_t * __restrict, int,
232 FILE * __restrict);
233ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict);
234
Ben Cheng09ebc132013-10-18 00:02:49 -0700235#if __BSD_VISIBLE && !defined(__SYS_ERRLIST)
236#define __SYS_ERRLIST
Ben Cheng09ebc132013-10-18 00:02:49 -0700237extern int sys_nerr; /* perror(3) external variables */
238extern char *sys_errlist[];
239#endif
Ben Cheng7334f0a2014-04-30 14:28:17 -0700240
Ben Cheng09ebc132013-10-18 00:02:49 -0700241void perror(const char *);
Ben Cheng7334f0a2014-04-30 14:28:17 -0700242int printf(const char * __restrict, ...)
243 __printflike(1, 2);
Ben Cheng09ebc132013-10-18 00:02:49 -0700244int putc(int, FILE *);
245int putchar(int);
246int puts(const char *);
247int remove(const char *);
Ben Cheng09ebc132013-10-18 00:02:49 -0700248void rewind(FILE *);
Ben Cheng7334f0a2014-04-30 14:28:17 -0700249int scanf(const char * __restrict, ...)
250 __scanflike(1, 2);
251void setbuf(FILE * __restrict, char * __restrict);
252int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
253int sscanf(const char * __restrict, const char * __restrict, ...)
254 __scanflike(2, 3);
Ben Cheng09ebc132013-10-18 00:02:49 -0700255FILE *tmpfile(void);
Ben Cheng09ebc132013-10-18 00:02:49 -0700256int ungetc(int, FILE *);
Ben Cheng7334f0a2014-04-30 14:28:17 -0700257int vfprintf(FILE * __restrict, const char * __restrict, __gnuc_va_list)
258 __printflike(2, 0);
259int vprintf(const char * __restrict, __gnuc_va_list)
260 __printflike(1, 0);
261
262#ifndef __AUDIT__
263char* gets(char*) __warnattr("gets is very unsafe; consider using fgets");
264int sprintf(char* __restrict, const char* __restrict, ...)
265 __printflike(2, 3); //__warnattr("sprintf is often misused; please use snprintf");
266char* tmpnam(char*) __warnattr("tmpnam possibly used unsafely; consider using mkstemp");
267int vsprintf(char* __restrict, const char* __restrict, __gnuc_va_list)
268 __printflike(2, 0); //__warnattr("vsprintf is often misused; please use vsnprintf");
269#if __XPG_VISIBLE
270char* tempnam(const char*, const char*)
271 __warnattr("tempnam possibly used unsafely; consider using mkstemp");
272#endif
273#endif
274
275extern int rename(const char*, const char*);
276extern int renameat(int, const char*, int, const char*);
277
278int fgetpos(FILE * __restrict, fpos_t * __restrict);
279int fsetpos(FILE *, const fpos_t *);
280
281int fseeko(FILE *, off_t, int);
282off_t ftello(FILE *);
Ben Cheng09ebc132013-10-18 00:02:49 -0700283
284#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE
Ben Cheng7334f0a2014-04-30 14:28:17 -0700285int snprintf(char * __restrict, size_t, const char * __restrict, ...)
286 __printflike(3, 4);
287int vfscanf(FILE * __restrict, const char * __restrict, __gnuc_va_list)
288 __scanflike(2, 0);
Ben Cheng09ebc132013-10-18 00:02:49 -0700289int vscanf(const char *, __gnuc_va_list)
Ben Cheng7334f0a2014-04-30 14:28:17 -0700290 __scanflike(1, 0);
291int vsnprintf(char * __restrict, size_t, const char * __restrict, __gnuc_va_list)
292 __printflike(3, 0);
293int vsscanf(const char * __restrict, const char * __restrict, __gnuc_va_list)
294 __scanflike(2, 0);
Ben Cheng09ebc132013-10-18 00:02:49 -0700295#endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */
296
297__END_DECLS
298
299
300/*
301 * Functions defined in POSIX 1003.1.
302 */
303#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
304#define L_ctermid 1024 /* size for ctermid(); PATH_MAX */
305#define L_cuserid 9 /* size for cuserid(); UT_NAMESIZE + 1 */
306
307__BEGIN_DECLS
308#if 0 /* MISSING FROM BIONIC */
309char *ctermid(char *);
310char *cuserid(char *);
311#endif /* MISSING */
312FILE *fdopen(int, const char *);
313int fileno(FILE *);
314
315#if (__POSIX_VISIBLE >= 199209)
316int pclose(FILE *);
317FILE *popen(const char *, const char *);
318#endif
319
320#if __POSIX_VISIBLE >= 199506
321void flockfile(FILE *);
322int ftrylockfile(FILE *);
323void funlockfile(FILE *);
324
325/*
326 * These are normally used through macros as defined below, but POSIX
327 * requires functions as well.
328 */
329int getc_unlocked(FILE *);
330int getchar_unlocked(void);
331int putc_unlocked(int, FILE *);
332int putchar_unlocked(int);
333#endif /* __POSIX_VISIBLE >= 199506 */
334
Ben Cheng09ebc132013-10-18 00:02:49 -0700335__END_DECLS
336
337#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
338
339/*
340 * Routines that are purely local.
341 */
342#if __BSD_VISIBLE
343__BEGIN_DECLS
Ben Cheng7334f0a2014-04-30 14:28:17 -0700344int asprintf(char ** __restrict, const char * __restrict, ...)
345 __printflike(2, 3);
346char *fgetln(FILE * __restrict, size_t * __restrict);
Ben Cheng09ebc132013-10-18 00:02:49 -0700347int fpurge(FILE *);
348int getw(FILE *);
349int putw(int, FILE *);
350void setbuffer(FILE *, char *, int);
351int setlinebuf(FILE *);
Ben Cheng7334f0a2014-04-30 14:28:17 -0700352int vasprintf(char ** __restrict, const char * __restrict,
353 __gnuc_va_list)
354 __printflike(2, 0);
Ben Cheng09ebc132013-10-18 00:02:49 -0700355__END_DECLS
356
357/*
358 * Stdio function-access interface.
359 */
360__BEGIN_DECLS
361FILE *funopen(const void *,
362 int (*)(void *, char *, int),
363 int (*)(void *, const char *, int),
364 fpos_t (*)(void *, fpos_t, int),
365 int (*)(void *));
366__END_DECLS
367#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
368#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
369#endif /* __BSD_VISIBLE */
370
Ben Cheng09ebc132013-10-18 00:02:49 -0700371#ifdef _GNU_SOURCE
372/*
373 * glibc defines dprintf(int, const char*, ...), which is poorly named
374 * and likely to conflict with locally defined debugging printfs
375 * fdprintf is a better name, and some programs that use fdprintf use a
376 * #define fdprintf dprintf for compatibility
377 */
Ben Cheng7334f0a2014-04-30 14:28:17 -0700378__BEGIN_DECLS
379int fdprintf(int, const char*, ...)
380 __printflike(2, 3);
381int vfdprintf(int, const char*, __gnuc_va_list)
382 __printflike(2, 0);
383__END_DECLS
Ben Cheng09ebc132013-10-18 00:02:49 -0700384#endif /* _GNU_SOURCE */
385
Ben Cheng7334f0a2014-04-30 14:28:17 -0700386#if defined(__BIONIC_FORTIFY)
387
388__BEGIN_DECLS
389
390__BIONIC_FORTIFY_INLINE
391__printflike(3, 0)
392int vsnprintf(char *dest, size_t size, const char *format, __va_list ap)
393{
394 return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap);
395}
396
397__BIONIC_FORTIFY_INLINE
398__printflike(2, 0)
399int vsprintf(char *dest, const char *format, __va_list ap)
400{
401 return __builtin___vsprintf_chk(dest, 0, __bos(dest), format, ap);
402}
403
404#if defined(__clang__)
405 #if !defined(snprintf)
406 #define __wrap_snprintf(dest, size, ...) __builtin___snprintf_chk(dest, size, 0, __bos(dest), __VA_ARGS__)
407 #define snprintf(...) __wrap_snprintf(__VA_ARGS__)
408 #endif
409#else
410__BIONIC_FORTIFY_INLINE
411__printflike(3, 4)
412int snprintf(char *dest, size_t size, const char *format, ...)
413{
414 return __builtin___snprintf_chk(dest, size, 0,
415 __bos(dest), format, __builtin_va_arg_pack());
416}
417#endif
418
419#if defined(__clang__)
420 #if !defined(sprintf)
421 #define __wrap_sprintf(dest, ...) __builtin___sprintf_chk(dest, 0, __bos(dest), __VA_ARGS__)
422 #define sprintf(...) __wrap_sprintf(__VA_ARGS__)
423 #endif
424#else
425__BIONIC_FORTIFY_INLINE
426__printflike(2, 3)
427int sprintf(char *dest, const char *format, ...)
428{
429 return __builtin___sprintf_chk(dest, 0,
430 __bos(dest), format, __builtin_va_arg_pack());
431}
432#endif
433
434extern char* __fgets_chk(char*, int, FILE*, size_t);
435extern char* __fgets_real(char*, int, FILE*) __asm__(__USER_LABEL_PREFIX__ "fgets");
436__errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
437__errordecl(__fgets_too_small_error, "fgets called with size less than zero");
438
439#if !defined(__clang__)
440
441__BIONIC_FORTIFY_INLINE
442char *fgets(char* dest, int size, FILE* stream) {
443 size_t bos = __bos(dest);
444
445 // Compiler can prove, at compile time, that the passed in size
446 // is always negative. Force a compiler error.
447 if (__builtin_constant_p(size) && (size < 0)) {
448 __fgets_too_small_error();
449 }
450
451 // Compiler doesn't know destination size. Don't call __fgets_chk
452 if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
453 return __fgets_real(dest, size, stream);
454 }
455
456 // Compiler can prove, at compile time, that the passed in size
457 // is always <= the actual object size. Don't call __fgets_chk
458 if (__builtin_constant_p(size) && (size <= (int) bos)) {
459 return __fgets_real(dest, size, stream);
460 }
461
462 // Compiler can prove, at compile time, that the passed in size
463 // is always > the actual object size. Force a compiler error.
464 if (__builtin_constant_p(size) && (size > (int) bos)) {
465 __fgets_too_big_error();
466 }
467
468 return __fgets_chk(dest, size, stream, bos);
469}
470
471#endif /* !defined(__clang__) */
472
473__END_DECLS
474
475#endif /* defined(__BIONIC_FORTIFY) */
476
Ben Cheng09ebc132013-10-18 00:02:49 -0700477#endif /* _STDIO_H_ */