blob: d2f2bd2456c11b784866d687e846bc946459d570 [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 Hughes7d56ccb2012-10-01 17:56:58 -070047#define __need_NULL
48#include <stddef.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080049
Elliott Hughesfd936ae2016-08-12 10:16:34 -070050#include <bits/seek_constants.h>
51
Elliott Hughes5bc78c82016-11-16 11:35:43 -080052#if __ANDROID_API__ < __ANDROID_API_N__
Dan Albert3037ea42016-10-06 15:46:45 -070053#include <bits/struct_file.h>
54#endif
55
Dan Albert658727e2014-10-07 11:10:36 -070056__BEGIN_DECLS
57
Elliott Hughes5470c182016-07-22 11:36:17 -070058#if defined(__clang__)
59#pragma clang diagnostic push
60#pragma clang diagnostic ignored "-Wnullability-completeness"
61#endif
62
Elliott Hughes9677fab2016-01-25 15:50:59 -080063typedef off_t fpos_t;
64typedef off64_t fpos64_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080065
Elliott Hughesf0141df2015-10-12 12:44:23 -070066struct __sFILE;
67typedef struct __sFILE FILE;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080068
Elliott Hughes5bc78c82016-11-16 11:35:43 -080069#if __ANDROID_API__ >= __ANDROID_API_M__
Josh Gao14adff12016-04-29 12:00:55 -070070extern FILE* stdin __INTRODUCED_IN(23);
71extern FILE* stdout __INTRODUCED_IN(23);
72extern FILE* stderr __INTRODUCED_IN(23);
Dan Albert32c79c22016-07-15 11:32:23 -070073
Elliott Hughes168667c2014-11-14 14:42:59 -080074/* 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 Albert32c79c22016-07-15 11:32:23 -070078#else
79/* Before M the actual symbols for stdin and friends had different names. */
Dan Albert3037ea42016-10-06 15:46:45 -070080extern FILE __sF[] __REMOVED_IN(23);
Dan Albert32c79c22016-07-15 11:32:23 -070081
Dan Albert3037ea42016-10-06 15:46:45 -070082#define stdin (&__sF[0])
83#define stdout (&__sF[1])
84#define stderr (&__sF[2])
Dan Albert32c79c22016-07-15 11:32:23 -070085#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080086
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080087/*
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 Project1dc9e472009-03-03 19:28:35 -0800101#define EOF (-1)
102
103/*
Elliott Hughesd04c1832013-05-14 16:08:43 -0700104 * 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 Project1dc9e472009-03-03 19:28:35 -0800107 */
Elliott Hughesd04c1832013-05-14 16:08:43 -0700108
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800109#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 Project1dc9e472009-03-03 19:28:35 -0800112#define L_tmpnam 1024 /* XXX must be == PATH_MAX */
113#define TMP_MAX 308915776
114
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800115/*
116 * Functions defined in ANSI C standard.
117 */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800118void clearerr(FILE *);
119int fclose(FILE *);
120int feof(FILE *);
121int ferror(FILE *);
122int fflush(FILE *);
123int fgetc(FILE *);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800124char *fgets(char * __restrict, int, FILE * __restrict) __overloadable
125 __RENAME_CLANG(fgets);
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700126int fprintf(FILE * __restrict , const char * __restrict _Nonnull, ...) __printflike(2, 3);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800127int fputc(int, FILE *);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700128int fputs(const char * __restrict, FILE * __restrict);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800129size_t fread(void * __restrict, size_t, size_t, FILE * __restrict)
130 __overloadable __RENAME_CLANG(fread);
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700131int fscanf(FILE * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800132size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict)
133 __overloadable __RENAME_CLANG(fwrite);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800134int getc(FILE *);
135int getchar(void);
Josh Gao46b44162016-05-27 11:14:16 -0700136ssize_t getdelim(char** __restrict, size_t* __restrict, int, FILE* __restrict) __INTRODUCED_IN(18);
137ssize_t getline(char** __restrict, size_t* __restrict, FILE* __restrict) __INTRODUCED_IN(18);
Elliott Hughesc13fb752013-12-17 20:43:30 -0800138
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800139void perror(const char *);
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700140int printf(const char * __restrict _Nonnull, ...) __printflike(1, 2);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800141int putc(int, FILE *);
142int putchar(int);
143int puts(const char *);
144int remove(const char *);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800145void rewind(FILE *);
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700146int scanf(const char * __restrict _Nonnull, ...) __scanflike(1, 2);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700147void setbuf(FILE * __restrict, char * __restrict);
148int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700149int sscanf(const char * __restrict, const char * __restrict _Nonnull, ...) __scanflike(2, 3);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800150int ungetc(int, FILE *);
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700151int vfprintf(FILE * __restrict, const char * __restrict _Nonnull, __va_list) __printflike(2, 0);
152int vprintf(const char * __restrict _Nonnull, __va_list) __printflike(1, 0);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700153
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700154int dprintf(int, const char* __restrict _Nonnull, ...) __printflike(2, 3) __INTRODUCED_IN(21);
155int vdprintf(int, const char* __restrict _Nonnull, __va_list) __printflike(2, 0) __INTRODUCED_IN(21);
Elliott Hughesfcac8ff2014-05-22 01:24:30 -0700156
Elliott Hughesf6495c72016-07-25 09:20:57 -0700157#if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \
158 (defined(__cplusplus) && __cplusplus <= 201103L)
Yabin Cui9b4f77f2015-02-23 16:42:07 -0800159char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead")));
Dan Albert96350462014-06-17 23:31:21 +0000160#endif
George Burgess IV7cc779f2017-02-09 00:00:31 -0800161int 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);
164int 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");
167char* tmpnam(char*)
168 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700169#define P_tmpdir "/tmp/" /* deprecated */
Elliott Hughesc13fb752013-12-17 20:43:30 -0800170char* tempnam(const char*, const char*)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800171 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
Elliott Hughesd04c1832013-05-14 16:08:43 -0700172
Elliott Hughes9677fab2016-01-25 15:50:59 -0800173int rename(const char*, const char*);
174int renameat(int, const char*, int, const char*);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700175
Elliott Hughes9677fab2016-01-25 15:50:59 -0800176int fseek(FILE*, long, int);
177long ftell(FILE*);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800178
Elliott Hughes00fedf52017-07-05 15:23:50 -0700179#if defined(__USE_FILE_OFFSET64)
180int fgetpos(FILE*, fpos_t*) __RENAME(fgetpos64) __INTRODUCED_IN(24);
181int fsetpos(FILE*, const fpos_t*) __RENAME(fsetpos64) __INTRODUCED_IN(24);
182int fseeko(FILE*, off_t, int) __RENAME(fseeko64) __INTRODUCED_IN(24);
183off_t ftello(FILE*) __RENAME(ftello64) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800184# if defined(__USE_BSD)
185FILE* funopen(const void*,
186 int (*)(void*, char*, int),
187 int (*)(void*, const char*, int),
188 fpos_t (*)(void*, fpos_t, int),
Elliott Hughes00fedf52017-07-05 15:23:50 -0700189 int (*)(void*)) __RENAME(funopen64) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800190# endif
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800191#else
Elliott Hughes9677fab2016-01-25 15:50:59 -0800192int fgetpos(FILE*, fpos_t*);
193int fsetpos(FILE*, const fpos_t*);
194int fseeko(FILE*, off_t, int);
195off_t ftello(FILE*);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800196# if defined(__USE_BSD)
197FILE* 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 Hughes68dc20d2015-02-06 22:28:49 -0800203#endif
Josh Gao14adff12016-04-29 12:00:55 -0700204int fgetpos64(FILE*, fpos64_t*) __INTRODUCED_IN(24);
205int fsetpos64(FILE*, const fpos64_t*) __INTRODUCED_IN(24);
206int fseeko64(FILE*, off64_t, int) __INTRODUCED_IN(24);
207off64_t ftello64(FILE*) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800208#if defined(__USE_BSD)
Josh Gao14adff12016-04-29 12:00:55 -0700209FILE* 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 Hughes03e65eb2016-01-26 14:13:04 -0800211#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800212
Elliott Hughesf226ee52016-02-03 11:24:28 -0800213FILE* fopen(const char* __restrict, const char* __restrict);
Josh Gao14adff12016-04-29 12:00:55 -0700214FILE* fopen64(const char* __restrict, const char* __restrict) __INTRODUCED_IN(24);
Elliott Hughesf226ee52016-02-03 11:24:28 -0800215FILE* freopen(const char* __restrict, const char* __restrict, FILE* __restrict);
Josh Gao14adff12016-04-29 12:00:55 -0700216FILE* freopen64(const char* __restrict, const char* __restrict, FILE* __restrict)
217 __INTRODUCED_IN(24);
Elliott Hughesf226ee52016-02-03 11:24:28 -0800218FILE* tmpfile(void);
Josh Gao14adff12016-04-29 12:00:55 -0700219FILE* tmpfile64(void) __INTRODUCED_IN(24);
Elliott Hughesf226ee52016-02-03 11:24:28 -0800220
George Burgess IV7cc779f2017-02-09 00:00:31 -0800221int snprintf(char* __restrict, size_t, const char* __restrict _Nonnull, ...)
222 __printflike(3, 4) __overloadable __RENAME_CLANG(snprintf);
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700223int vfscanf(FILE* __restrict, const char* __restrict _Nonnull, __va_list) __scanflike(2, 0);
224int vscanf(const char* _Nonnull , __va_list) __scanflike(1, 0);
George Burgess IV7cc779f2017-02-09 00:00:31 -0800225int vsnprintf(char* __restrict, size_t, const char* __restrict _Nonnull, __va_list)
226 __printflike(3, 0) __overloadable __RENAME_CLANG(vsnprintf);
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700227int vsscanf(const char* __restrict _Nonnull, const char* __restrict _Nonnull, __va_list) __scanflike(2, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800228
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700229#define L_ctermid 1024 /* size for ctermid() */
Josh Gao2e8e5e62017-04-20 12:58:31 -0700230char* ctermid(char*) __INTRODUCED_IN(26);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800231
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700232FILE* fdopen(int, const char*);
233int fileno(FILE*);
234int pclose(FILE*);
235FILE* popen(const char*, const char*);
236void flockfile(FILE*);
237int ftrylockfile(FILE*);
238void funlockfile(FILE*);
239int getc_unlocked(FILE*);
240int getchar_unlocked(void);
241int putc_unlocked(int, FILE*);
242int putchar_unlocked(int);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800243
Josh Gao14adff12016-04-29 12:00:55 -0700244FILE* fmemopen(void*, size_t, const char*) __INTRODUCED_IN(23);
245FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800246
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700247#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700248int asprintf(char** __restrict, const char* __restrict _Nonnull, ...) __printflike(2, 3);
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700249char* fgetln(FILE* __restrict, size_t* __restrict);
250int fpurge(FILE*);
251void setbuffer(FILE*, char*, int);
252int setlinebuf(FILE*);
Elliott Hughes9eb3ae12016-06-30 09:12:40 -0700253int vasprintf(char** __restrict, const char* __restrict _Nonnull, __va_list) __printflike(2, 0);
Josh Gao14adff12016-04-29 12:00:55 -0700254void clearerr_unlocked(FILE*) __INTRODUCED_IN(23);
255int feof_unlocked(FILE*) __INTRODUCED_IN(23);
256int ferror_unlocked(FILE*) __INTRODUCED_IN(23);
257int fileno_unlocked(FILE*) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800258#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
259#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700260#endif /* __USE_BSD */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800261
George Burgess IVb97049c2017-07-24 15:05:05 -0700262#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
263#include <bits/fortify/stdio.h>
264#endif
Nick Kralevichcffdf662012-06-11 15:50:57 -0700265
Elliott Hughes5470c182016-07-22 11:36:17 -0700266#if defined(__clang__)
267#pragma clang diagnostic pop
268#endif
269
Dan Albert658727e2014-10-07 11:10:36 -0700270__END_DECLS
271
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800272#endif /* _STDIO_H_ */