blob: 4dff48daf2054bddf3fe08b434cefa3ff6d1da59 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/* $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 Hughes3975cec2012-11-29 17:25:23 -080042#include <sys/types.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080043
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044#include <stdarg.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080045#include <stddef.h>
46
Elliott Hughesfd936ae2016-08-12 10:16:34 -070047#include <bits/seek_constants.h>
48
Elliott Hughes5bc78c82016-11-16 11:35:43 -080049#if __ANDROID_API__ < __ANDROID_API_N__
Dan Albert3037ea42016-10-06 15:46:45 -070050#include <bits/struct_file.h>
51#endif
52
Dan Albert658727e2014-10-07 11:10:36 -070053__BEGIN_DECLS
54
Elliott Hughes9677fab2016-01-25 15:50:59 -080055typedef off_t fpos_t;
56typedef off64_t fpos64_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057
Elliott Hughesf0141df2015-10-12 12:44:23 -070058struct __sFILE;
59typedef struct __sFILE FILE;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080060
Elliott Hughes5bc78c82016-11-16 11:35:43 -080061#if __ANDROID_API__ >= __ANDROID_API_M__
Josh Gao14adff12016-04-29 12:00:55 -070062extern FILE* stdin __INTRODUCED_IN(23);
63extern FILE* stdout __INTRODUCED_IN(23);
64extern FILE* stderr __INTRODUCED_IN(23);
Dan Albert32c79c22016-07-15 11:32:23 -070065
Elliott Hughes168667c2014-11-14 14:42:59 -080066/* C99 and earlier plus current C++ standards say these must be macros. */
67#define stdin stdin
68#define stdout stdout
69#define stderr stderr
Dan Albert32c79c22016-07-15 11:32:23 -070070#else
71/* Before M the actual symbols for stdin and friends had different names. */
Dan Albert3037ea42016-10-06 15:46:45 -070072extern FILE __sF[] __REMOVED_IN(23);
Dan Albert32c79c22016-07-15 11:32:23 -070073
Dan Albert3037ea42016-10-06 15:46:45 -070074#define stdin (&__sF[0])
75#define stdout (&__sF[1])
76#define stderr (&__sF[2])
Dan Albert32c79c22016-07-15 11:32:23 -070077#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080078
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079/*
80 * The following three definitions are for ANSI C, which took them
81 * from System V, which brilliantly took internal interface macros and
82 * made them official arguments to setvbuf(), without renaming them.
83 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
84 *
85 * Although numbered as their counterparts above, the implementation
86 * does not rely on this.
87 */
88#define _IOFBF 0 /* setvbuf should set fully buffered */
89#define _IOLBF 1 /* setvbuf should set line buffered */
90#define _IONBF 2 /* setvbuf should set unbuffered */
91
92#define BUFSIZ 1024 /* size of buffer used by setbuf */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080093#define EOF (-1)
94
95/*
Elliott Hughesd04c1832013-05-14 16:08:43 -070096 * FOPEN_MAX is a minimum maximum, and is the number of streams that
97 * stdio can provide without attempting to allocate further resources
98 * (which could fail). Do not use this for anything.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080099 */
Elliott Hughesb15feb72017-07-31 17:20:18 -0700100#define FOPEN_MAX 20
101#define FILENAME_MAX 4096
Elliott Hughesd04c1832013-05-14 16:08:43 -0700102
Elliott Hughesb15feb72017-07-31 17:20:18 -0700103#define L_tmpnam 4096
104#define TMP_MAX 308915776
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800105
Colin Cross9af91202017-08-17 18:29:54 +0000106/*
107 * Functions defined in ANSI C standard.
108 */
109void clearerr(FILE *);
110int fclose(FILE *);
111int feof(FILE *);
112int ferror(FILE *);
113int fflush(FILE *);
114int fgetc(FILE *);
115char *fgets(char *, int, FILE *) __overloadable
116 __RENAME_CLANG(fgets);
117int fprintf(FILE * , const char *, ...) __printflike(2, 3);
118int fputc(int, FILE *);
119int fputs(const char *, FILE *);
120size_t fread(void *, size_t, size_t, FILE *)
121 __overloadable __RENAME_CLANG(fread);
122int fscanf(FILE *, const char *, ...) __scanflike(2, 3);
123size_t fwrite(const void *, size_t, size_t, FILE *)
124 __overloadable __RENAME_CLANG(fwrite);
125int getc(FILE *);
126int getchar(void);
127ssize_t getdelim(char**, size_t*, int, FILE*) __INTRODUCED_IN(18);
128ssize_t getline(char**, size_t*, FILE*) __INTRODUCED_IN(18);
Elliott Hughesc13fb752013-12-17 20:43:30 -0800129
Colin Cross9af91202017-08-17 18:29:54 +0000130void perror(const char *);
131int printf(const char *, ...) __printflike(1, 2);
132int putc(int, FILE *);
133int putchar(int);
134int puts(const char *);
135int remove(const char *);
136void rewind(FILE *);
137int scanf(const char *, ...) __scanflike(1, 2);
138void setbuf(FILE *, char *);
139int setvbuf(FILE *, char *, int, size_t);
140int sscanf(const char *, const char *, ...) __scanflike(2, 3);
141int ungetc(int, FILE *);
142int vfprintf(FILE *, const char *, va_list) __printflike(2, 0);
143int vprintf(const char *, va_list) __printflike(1, 0);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700144
Dan Albert5f7135e2017-07-26 14:09:45 -0700145#if __ANDROID_API__ >= 21
Colin Cross9af91202017-08-17 18:29:54 +0000146int dprintf(int, const char*, ...) __printflike(2, 3) __INTRODUCED_IN(21);
147int vdprintf(int, const char*, va_list) __printflike(2, 0) __INTRODUCED_IN(21);
Dan Albert5f7135e2017-07-26 14:09:45 -0700148#else
149/*
150 * Old versions of Android called these fdprintf and vfdprintf out of fears that the glibc names
151 * would collide with user debug printfs.
152 *
153 * Allow users to just use dprintf and vfdprintf on any version by renaming those calls to their
154 * legacy equivalents if needed.
155 */
Colin Cross9af91202017-08-17 18:29:54 +0000156int dprintf(int, const char*, ...) __RENAME(fdprintf) __printflike(2, 3);
157int vdprintf(int, const char*, va_list) __RENAME(vfdprintf) __printflike(2, 0);
Dan Albert5f7135e2017-07-26 14:09:45 -0700158#endif
Elliott Hughesfcac8ff2014-05-22 01:24:30 -0700159
Elliott Hughesf6495c72016-07-25 09:20:57 -0700160#if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \
161 (defined(__cplusplus) && __cplusplus <= 201103L)
Colin Cross9af91202017-08-17 18:29:54 +0000162char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead")));
Dan Albert96350462014-06-17 23:31:21 +0000163#endif
Colin Cross9af91202017-08-17 18:29:54 +0000164int sprintf(char*, const char*, ...)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800165 __printflike(2, 3) __warnattr_strict("sprintf is often misused; please use snprintf")
166 __overloadable __RENAME_CLANG(sprintf);
Colin Cross9af91202017-08-17 18:29:54 +0000167int vsprintf(char*, const char*, va_list)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800168 __overloadable __printflike(2, 0) __RENAME_CLANG(vsprintf)
169 __warnattr_strict("vsprintf is often misused; please use vsnprintf");
Colin Cross9af91202017-08-17 18:29:54 +0000170char* tmpnam(char*)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800171 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700172#define P_tmpdir "/tmp/" /* deprecated */
Colin Cross9af91202017-08-17 18:29:54 +0000173char* tempnam(const char*, const char*)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800174 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
Elliott Hughesd04c1832013-05-14 16:08:43 -0700175
Colin Cross9af91202017-08-17 18:29:54 +0000176int rename(const char*, const char*);
177int renameat(int, const char*, int, const char*);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700178
Colin Cross9af91202017-08-17 18:29:54 +0000179int fseek(FILE*, long, int);
180long ftell(FILE*);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800181
Elliott Hughes00fedf52017-07-05 15:23:50 -0700182#if defined(__USE_FILE_OFFSET64)
Colin Cross9af91202017-08-17 18:29:54 +0000183int fgetpos(FILE*, fpos_t*) __RENAME(fgetpos64) __INTRODUCED_IN(24);
184int fsetpos(FILE*, const fpos_t*) __RENAME(fsetpos64) __INTRODUCED_IN(24);
185int fseeko(FILE*, off_t, int) __RENAME(fseeko64) __INTRODUCED_IN(24);
186off_t ftello(FILE*) __RENAME(ftello64) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800187# if defined(__USE_BSD)
Colin Cross9af91202017-08-17 18:29:54 +0000188FILE* funopen(const void*,
189 int (*)(void*, char*, int),
190 int (*)(void*, const char*, int),
191 fpos_t (*)(void*, fpos_t, int),
192 int (*)(void*)) __RENAME(funopen64) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800193# endif
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800194#else
Colin Cross9af91202017-08-17 18:29:54 +0000195int fgetpos(FILE*, fpos_t*);
196int fsetpos(FILE*, const fpos_t*);
197int fseeko(FILE*, off_t, int);
198off_t ftello(FILE*);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800199# if defined(__USE_BSD)
Colin Cross9af91202017-08-17 18:29:54 +0000200FILE* funopen(const void*,
201 int (*)(void*, char*, int),
202 int (*)(void*, const char*, int),
203 fpos_t (*)(void*, fpos_t, int),
204 int (*)(void*));
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800205# endif
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800206#endif
Colin Cross9af91202017-08-17 18:29:54 +0000207int fgetpos64(FILE*, fpos64_t*) __INTRODUCED_IN(24);
208int fsetpos64(FILE*, const fpos64_t*) __INTRODUCED_IN(24);
209int fseeko64(FILE*, off64_t, int) __INTRODUCED_IN(24);
210off64_t ftello64(FILE*) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800211#if defined(__USE_BSD)
Colin Cross9af91202017-08-17 18:29:54 +0000212FILE* funopen64(const void*, int (*)(void*, char*, int), int (*)(void*, const char*, int),
213 fpos64_t (*)(void*, fpos64_t, int), int (*)(void*)) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800214#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800215
Colin Cross9af91202017-08-17 18:29:54 +0000216FILE* fopen(const char*, const char*);
217FILE* fopen64(const char*, const char*) __INTRODUCED_IN(24);
218FILE* freopen(const char*, const char*, FILE*);
219FILE* freopen64(const char*, const char*, FILE*)
220 __INTRODUCED_IN(24);
Elliott Hughesf226ee52016-02-03 11:24:28 -0800221FILE* tmpfile(void);
Josh Gao14adff12016-04-29 12:00:55 -0700222FILE* tmpfile64(void) __INTRODUCED_IN(24);
Elliott Hughesf226ee52016-02-03 11:24:28 -0800223
Colin Cross9af91202017-08-17 18:29:54 +0000224int snprintf(char*, size_t, const char*, ...)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800225 __printflike(3, 4) __overloadable __RENAME_CLANG(snprintf);
Colin Cross9af91202017-08-17 18:29:54 +0000226int vfscanf(FILE*, const char*, va_list) __scanflike(2, 0);
227int vscanf(const char* , va_list) __scanflike(1, 0);
228int vsnprintf(char*, size_t, const char*, va_list)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800229 __printflike(3, 0) __overloadable __RENAME_CLANG(vsnprintf);
Colin Cross9af91202017-08-17 18:29:54 +0000230int vsscanf(const char*, const char*, va_list) __scanflike(2, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800231
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700232#define L_ctermid 1024 /* size for ctermid() */
Colin Cross9af91202017-08-17 18:29:54 +0000233char* ctermid(char*) __INTRODUCED_IN(26);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800234
Colin Cross9af91202017-08-17 18:29:54 +0000235FILE* fdopen(int, const char*);
236int fileno(FILE*);
237int pclose(FILE*);
238FILE* popen(const char*, const char*);
239void flockfile(FILE*);
240int ftrylockfile(FILE*);
241void funlockfile(FILE*);
242int getc_unlocked(FILE*);
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700243int getchar_unlocked(void);
Colin Cross9af91202017-08-17 18:29:54 +0000244int putc_unlocked(int, FILE*);
245int putchar_unlocked(int);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800246
Colin Cross9af91202017-08-17 18:29:54 +0000247FILE* fmemopen(void*, size_t, const char*) __INTRODUCED_IN(23);
248FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800249
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700250#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
Colin Cross9af91202017-08-17 18:29:54 +0000251int asprintf(char**, const char*, ...) __printflike(2, 3);
252char* fgetln(FILE*, size_t*);
253int fpurge(FILE*);
254void setbuffer(FILE*, char*, int);
255int setlinebuf(FILE*);
256int vasprintf(char**, const char*, va_list) __printflike(2, 0);
257void clearerr_unlocked(FILE*) __INTRODUCED_IN(23);
258int feof_unlocked(FILE*) __INTRODUCED_IN(23);
259int ferror_unlocked(FILE*) __INTRODUCED_IN(23);
260int fileno_unlocked(FILE*) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800261#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
262#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700263#endif /* __USE_BSD */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800264
George Burgess IVb97049c2017-07-24 15:05:05 -0700265#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
266#include <bits/fortify/stdio.h>
267#endif
Nick Kralevichcffdf662012-06-11 15:50:57 -0700268
Dan Albert658727e2014-10-07 11:10:36 -0700269__END_DECLS
270
Colin Cross9af91202017-08-17 18:29:54 +0000271#endif /* _STDIO_H_ */