blob: a9bb1242a99c8afa6b9c02ad874ad437c312965c [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 Hughes5470c182016-07-22 11:36:17 -070055#if defined(__clang__)
56#pragma clang diagnostic push
57#pragma clang diagnostic ignored "-Wnullability-completeness"
58#endif
59
Elliott Hughes9677fab2016-01-25 15:50:59 -080060typedef off_t fpos_t;
61typedef off64_t fpos64_t;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080062
Elliott Hughesf0141df2015-10-12 12:44:23 -070063struct __sFILE;
64typedef struct __sFILE FILE;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080065
Elliott Hughes5bc78c82016-11-16 11:35:43 -080066#if __ANDROID_API__ >= __ANDROID_API_M__
Josh Gao14adff12016-04-29 12:00:55 -070067extern FILE* stdin __INTRODUCED_IN(23);
68extern FILE* stdout __INTRODUCED_IN(23);
69extern FILE* stderr __INTRODUCED_IN(23);
Dan Albert32c79c22016-07-15 11:32:23 -070070
Elliott Hughes168667c2014-11-14 14:42:59 -080071/* C99 and earlier plus current C++ standards say these must be macros. */
72#define stdin stdin
73#define stdout stdout
74#define stderr stderr
Dan Albert32c79c22016-07-15 11:32:23 -070075#else
76/* Before M the actual symbols for stdin and friends had different names. */
Dan Albert3037ea42016-10-06 15:46:45 -070077extern FILE __sF[] __REMOVED_IN(23);
Dan Albert32c79c22016-07-15 11:32:23 -070078
Dan Albert3037ea42016-10-06 15:46:45 -070079#define stdin (&__sF[0])
80#define stdout (&__sF[1])
81#define stderr (&__sF[2])
Dan Albert32c79c22016-07-15 11:32:23 -070082#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080083
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080084/*
85 * The following three definitions are for ANSI C, which took them
86 * from System V, which brilliantly took internal interface macros and
87 * made them official arguments to setvbuf(), without renaming them.
88 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
89 *
90 * Although numbered as their counterparts above, the implementation
91 * does not rely on this.
92 */
93#define _IOFBF 0 /* setvbuf should set fully buffered */
94#define _IOLBF 1 /* setvbuf should set line buffered */
95#define _IONBF 2 /* setvbuf should set unbuffered */
96
97#define BUFSIZ 1024 /* size of buffer used by setbuf */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080098#define EOF (-1)
99
100/*
Elliott Hughesd04c1832013-05-14 16:08:43 -0700101 * FOPEN_MAX is a minimum maximum, and is the number of streams that
102 * stdio can provide without attempting to allocate further resources
103 * (which could fail). Do not use this for anything.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800104 */
Elliott Hughesb15feb72017-07-31 17:20:18 -0700105#define FOPEN_MAX 20
106#define FILENAME_MAX 4096
Elliott Hughesd04c1832013-05-14 16:08:43 -0700107
Elliott Hughesb15feb72017-07-31 17:20:18 -0700108#define L_tmpnam 4096
109#define TMP_MAX 308915776
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800110
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800111/*
112 * Functions defined in ANSI C standard.
113 */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800114void clearerr(FILE *);
115int fclose(FILE *);
116int feof(FILE *);
117int ferror(FILE *);
118int fflush(FILE *);
119int fgetc(FILE *);
Elliott Hughesec6850d2017-08-01 08:28:46 -0700120char *fgets(char *, int, FILE *) __overloadable
George Burgess IV7cc779f2017-02-09 00:00:31 -0800121 __RENAME_CLANG(fgets);
Elliott Hughesec6850d2017-08-01 08:28:46 -0700122int fprintf(FILE * , const char * _Nonnull, ...) __printflike(2, 3);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800123int fputc(int, FILE *);
Elliott Hughesec6850d2017-08-01 08:28:46 -0700124int fputs(const char *, FILE *);
125size_t fread(void *, size_t, size_t, FILE *)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800126 __overloadable __RENAME_CLANG(fread);
Elliott Hughesec6850d2017-08-01 08:28:46 -0700127int fscanf(FILE *, const char * _Nonnull, ...) __scanflike(2, 3);
128size_t fwrite(const void *, size_t, size_t, FILE *)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800129 __overloadable __RENAME_CLANG(fwrite);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800130int getc(FILE *);
131int getchar(void);
Elliott Hughesec6850d2017-08-01 08:28:46 -0700132ssize_t getdelim(char**, size_t*, int, FILE*) __INTRODUCED_IN(18);
133ssize_t getline(char**, size_t*, FILE*) __INTRODUCED_IN(18);
Elliott Hughesc13fb752013-12-17 20:43:30 -0800134
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800135void perror(const char *);
Elliott Hughesec6850d2017-08-01 08:28:46 -0700136int printf(const char * _Nonnull, ...) __printflike(1, 2);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800137int putc(int, FILE *);
138int putchar(int);
139int puts(const char *);
140int remove(const char *);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800141void rewind(FILE *);
Elliott Hughesec6850d2017-08-01 08:28:46 -0700142int scanf(const char * _Nonnull, ...) __scanflike(1, 2);
143void setbuf(FILE *, char *);
144int setvbuf(FILE *, char *, int, size_t);
145int sscanf(const char *, const char * _Nonnull, ...) __scanflike(2, 3);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800146int ungetc(int, FILE *);
Elliott Hughes4a8de0d2017-08-01 10:48:08 -0700147int vfprintf(FILE *, const char * _Nonnull, va_list) __printflike(2, 0);
148int vprintf(const char * _Nonnull, va_list) __printflike(1, 0);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700149
Dan Albert5f7135e2017-07-26 14:09:45 -0700150#if __ANDROID_API__ >= 21
Elliott Hughesec6850d2017-08-01 08:28:46 -0700151int dprintf(int, const char* _Nonnull, ...) __printflike(2, 3) __INTRODUCED_IN(21);
Elliott Hughes4a8de0d2017-08-01 10:48:08 -0700152int vdprintf(int, const char* _Nonnull, va_list) __printflike(2, 0) __INTRODUCED_IN(21);
Dan Albert5f7135e2017-07-26 14:09:45 -0700153#else
154/*
155 * Old versions of Android called these fdprintf and vfdprintf out of fears that the glibc names
156 * would collide with user debug printfs.
157 *
158 * Allow users to just use dprintf and vfdprintf on any version by renaming those calls to their
159 * legacy equivalents if needed.
160 */
Elliott Hughesec6850d2017-08-01 08:28:46 -0700161int dprintf(int, const char* _Nonnull, ...) __printflike(2, 3) __RENAME(fdprintf);
Elliott Hughes4a8de0d2017-08-01 10:48:08 -0700162int vdprintf(int, const char* _Nonnull, va_list) __printflike(2, 0) __RENAME(vfdprintf);
Dan Albert5f7135e2017-07-26 14:09:45 -0700163#endif
Elliott Hughesfcac8ff2014-05-22 01:24:30 -0700164
Elliott Hughesf6495c72016-07-25 09:20:57 -0700165#if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \
166 (defined(__cplusplus) && __cplusplus <= 201103L)
Yabin Cui9b4f77f2015-02-23 16:42:07 -0800167char* gets(char*) __attribute__((deprecated("gets is unsafe, use fgets instead")));
Dan Albert96350462014-06-17 23:31:21 +0000168#endif
Elliott Hughesec6850d2017-08-01 08:28:46 -0700169int sprintf(char*, const char* _Nonnull, ...)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800170 __printflike(2, 3) __warnattr_strict("sprintf is often misused; please use snprintf")
171 __overloadable __RENAME_CLANG(sprintf);
Elliott Hughes4a8de0d2017-08-01 10:48:08 -0700172int vsprintf(char*, const char* _Nonnull, va_list)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800173 __overloadable __printflike(2, 0) __RENAME_CLANG(vsprintf)
174 __warnattr_strict("vsprintf is often misused; please use vsnprintf");
175char* tmpnam(char*)
176 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700177#define P_tmpdir "/tmp/" /* deprecated */
Elliott Hughesc13fb752013-12-17 20:43:30 -0800178char* tempnam(const char*, const char*)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800179 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
Elliott Hughesd04c1832013-05-14 16:08:43 -0700180
Elliott Hughes9677fab2016-01-25 15:50:59 -0800181int rename(const char*, const char*);
182int renameat(int, const char*, int, const char*);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700183
Elliott Hughes9677fab2016-01-25 15:50:59 -0800184int fseek(FILE*, long, int);
185long ftell(FILE*);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800186
Elliott Hughes00fedf52017-07-05 15:23:50 -0700187#if defined(__USE_FILE_OFFSET64)
188int fgetpos(FILE*, fpos_t*) __RENAME(fgetpos64) __INTRODUCED_IN(24);
189int fsetpos(FILE*, const fpos_t*) __RENAME(fsetpos64) __INTRODUCED_IN(24);
190int fseeko(FILE*, off_t, int) __RENAME(fseeko64) __INTRODUCED_IN(24);
191off_t ftello(FILE*) __RENAME(ftello64) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800192# if defined(__USE_BSD)
193FILE* funopen(const void*,
194 int (*)(void*, char*, int),
195 int (*)(void*, const char*, int),
196 fpos_t (*)(void*, fpos_t, int),
Elliott Hughes00fedf52017-07-05 15:23:50 -0700197 int (*)(void*)) __RENAME(funopen64) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800198# endif
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800199#else
Elliott Hughes9677fab2016-01-25 15:50:59 -0800200int fgetpos(FILE*, fpos_t*);
201int fsetpos(FILE*, const fpos_t*);
202int fseeko(FILE*, off_t, int);
203off_t ftello(FILE*);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800204# if defined(__USE_BSD)
205FILE* funopen(const void*,
206 int (*)(void*, char*, int),
207 int (*)(void*, const char*, int),
208 fpos_t (*)(void*, fpos_t, int),
209 int (*)(void*));
210# endif
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800211#endif
Josh Gao14adff12016-04-29 12:00:55 -0700212int fgetpos64(FILE*, fpos64_t*) __INTRODUCED_IN(24);
213int fsetpos64(FILE*, const fpos64_t*) __INTRODUCED_IN(24);
214int fseeko64(FILE*, off64_t, int) __INTRODUCED_IN(24);
215off64_t ftello64(FILE*) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800216#if defined(__USE_BSD)
Josh Gao14adff12016-04-29 12:00:55 -0700217FILE* funopen64(const void*, int (*)(void*, char*, int), int (*)(void*, const char*, int),
218 fpos64_t (*)(void*, fpos64_t, int), int (*)(void*)) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800219#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800220
Elliott Hughesec6850d2017-08-01 08:28:46 -0700221FILE* fopen(const char*, const char*);
222FILE* fopen64(const char*, const char*) __INTRODUCED_IN(24);
223FILE* freopen(const char*, const char*, FILE*);
224FILE* freopen64(const char*, const char*, FILE*)
Josh Gao14adff12016-04-29 12:00:55 -0700225 __INTRODUCED_IN(24);
Elliott Hughesf226ee52016-02-03 11:24:28 -0800226FILE* tmpfile(void);
Josh Gao14adff12016-04-29 12:00:55 -0700227FILE* tmpfile64(void) __INTRODUCED_IN(24);
Elliott Hughesf226ee52016-02-03 11:24:28 -0800228
Elliott Hughesec6850d2017-08-01 08:28:46 -0700229int snprintf(char*, size_t, const char* _Nonnull, ...)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800230 __printflike(3, 4) __overloadable __RENAME_CLANG(snprintf);
Elliott Hughes4a8de0d2017-08-01 10:48:08 -0700231int vfscanf(FILE*, const char* _Nonnull, va_list) __scanflike(2, 0);
232int vscanf(const char* _Nonnull , va_list) __scanflike(1, 0);
233int vsnprintf(char*, size_t, const char* _Nonnull, va_list)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800234 __printflike(3, 0) __overloadable __RENAME_CLANG(vsnprintf);
Elliott Hughes4a8de0d2017-08-01 10:48:08 -0700235int vsscanf(const char* _Nonnull, const char* _Nonnull, va_list) __scanflike(2, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800236
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700237#define L_ctermid 1024 /* size for ctermid() */
Josh Gao2e8e5e62017-04-20 12:58:31 -0700238char* ctermid(char*) __INTRODUCED_IN(26);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800239
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700240FILE* fdopen(int, const char*);
241int fileno(FILE*);
242int pclose(FILE*);
243FILE* popen(const char*, const char*);
244void flockfile(FILE*);
245int ftrylockfile(FILE*);
246void funlockfile(FILE*);
247int getc_unlocked(FILE*);
248int getchar_unlocked(void);
249int putc_unlocked(int, FILE*);
250int putchar_unlocked(int);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800251
Josh Gao14adff12016-04-29 12:00:55 -0700252FILE* fmemopen(void*, size_t, const char*) __INTRODUCED_IN(23);
253FILE* open_memstream(char**, size_t*) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800254
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700255#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
Elliott Hughesec6850d2017-08-01 08:28:46 -0700256int asprintf(char**, const char* _Nonnull, ...) __printflike(2, 3);
257char* fgetln(FILE*, size_t*);
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700258int fpurge(FILE*);
259void setbuffer(FILE*, char*, int);
260int setlinebuf(FILE*);
Elliott Hughes4a8de0d2017-08-01 10:48:08 -0700261int vasprintf(char**, const char* _Nonnull, va_list) __printflike(2, 0);
Josh Gao14adff12016-04-29 12:00:55 -0700262void clearerr_unlocked(FILE*) __INTRODUCED_IN(23);
263int feof_unlocked(FILE*) __INTRODUCED_IN(23);
264int ferror_unlocked(FILE*) __INTRODUCED_IN(23);
265int fileno_unlocked(FILE*) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800266#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
267#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700268#endif /* __USE_BSD */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800269
George Burgess IVb97049c2017-07-24 15:05:05 -0700270#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
271#include <bits/fortify/stdio.h>
272#endif
Nick Kralevichcffdf662012-06-11 15:50:57 -0700273
Elliott Hughes5470c182016-07-22 11:36:17 -0700274#if defined(__clang__)
275#pragma clang diagnostic pop
276#endif
277
Dan Albert658727e2014-10-07 11:10:36 -0700278__END_DECLS
279
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800280#endif /* _STDIO_H_ */