blob: 2c2dc0173f037c581274058467850128de92a0c6 [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 Hughes95c6cd72019-12-20 13:26:14 -080049#if __ANDROID_API__ < 24
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 Hughes95c6cd72019-12-20 13:26:14 -080061#if __ANDROID_API__ >= 23
zijunzhao00a3dba2023-03-01 00:07:40 +000062extern FILE* _Nonnull stdin __INTRODUCED_IN(23);
63extern FILE* _Nonnull stdout __INTRODUCED_IN(23);
64extern FILE* _Nonnull 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 Albertcc86c742024-05-02 18:53:45 +000072extern FILE __sF[] __REMOVED_IN(23, "Use stdin/stdout/stderr");
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
zijunzhao00a3dba2023-03-01 00:07:40 +0000106void clearerr(FILE* _Nonnull __fp);
107int fclose(FILE* _Nonnull __fp);
Elliott Hughesb19df892024-09-06 14:27:41 +0000108__nodiscard int feof(FILE* _Nonnull __fp);
109__nodiscard int ferror(FILE* _Nonnull __fp);
zijunzhao00a3dba2023-03-01 00:07:40 +0000110int fflush(FILE* _Nullable __fp);
Elliott Hughesb19df892024-09-06 14:27:41 +0000111__nodiscard int fgetc(FILE* _Nonnull __fp);
zijunzhao00a3dba2023-03-01 00:07:40 +0000112char* _Nullable fgets(char* _Nonnull __buf, int __size, FILE* _Nonnull __fp);
113int fprintf(FILE* _Nonnull __fp , const char* _Nonnull __fmt, ...) __printflike(2, 3);
114int fputc(int __ch, FILE* _Nonnull __fp);
115int fputs(const char* _Nonnull __s, FILE* _Nonnull __fp);
116size_t fread(void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp);
117int fscanf(FILE* _Nonnull __fp, const char* _Nonnull __fmt, ...) __scanflike(2, 3);
118size_t fwrite(const void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp);
Elliott Hughesb19df892024-09-06 14:27:41 +0000119__nodiscard int getc(FILE* _Nonnull __fp);
120__nodiscard int getchar(void);
Elliott Hughes655e4302023-06-16 12:39:33 -0700121ssize_t getdelim(char* _Nullable * _Nonnull __line_ptr, size_t* _Nonnull __line_length_ptr, int __delimiter, FILE* _Nonnull __fp);
122ssize_t getline(char* _Nullable * _Nonnull __line_ptr, size_t* _Nonnull __line_length_ptr, FILE* _Nonnull __fp);
Elliott Hughesc13fb752013-12-17 20:43:30 -0800123
zijunzhao00a3dba2023-03-01 00:07:40 +0000124void perror(const char* _Nullable __msg);
125int printf(const char* _Nonnull __fmt, ...) __printflike(1, 2);
126int putc(int __ch, FILE* _Nonnull __fp);
Elliott Hughesff26a162017-08-17 22:34:21 +0000127int putchar(int __ch);
zijunzhao00a3dba2023-03-01 00:07:40 +0000128int puts(const char* _Nonnull __s);
129int remove(const char* _Nonnull __path);
130void rewind(FILE* _Nonnull __fp);
131int scanf(const char* _Nonnull __fmt, ...) __scanflike(1, 2);
132void setbuf(FILE* _Nonnull __fp, char* _Nullable __buf);
133int setvbuf(FILE* _Nonnull __fp, char* _Nullable __buf, int __mode, size_t __size);
134int sscanf(const char* _Nonnull __s, const char* _Nonnull __fmt, ...) __scanflike(2, 3);
135int ungetc(int __ch, FILE* _Nonnull __fp);
136int vfprintf(FILE* _Nonnull __fp, const char* _Nonnull __fmt, va_list __args) __printflike(2, 0);
137int vprintf(const char* _Nonnull __fp, va_list __args) __printflike(1, 0);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700138
Elliott Hughes655e4302023-06-16 12:39:33 -0700139int dprintf(int __fd, const char* _Nonnull __fmt, ...) __printflike(2, 3);
140int vdprintf(int __fd, const char* _Nonnull __fmt, va_list __args) __printflike(2, 0);
Elliott Hughesfcac8ff2014-05-22 01:24:30 -0700141
Elliott Hughesf6495c72016-07-25 09:20:57 -0700142#if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L) || \
143 (defined(__cplusplus) && __cplusplus <= 201103L)
Elliott Hughesa1b5ca22024-04-22 20:10:53 +0000144char* _Nullable gets(char* _Nonnull __buf) __attribute__((__deprecated__("gets is unsafe, use fgets instead")));
Dan Albert96350462014-06-17 23:31:21 +0000145#endif
zijunzhaoe1833e52023-04-26 21:43:30 +0000146int sprintf(char* __BIONIC_COMPLICATED_NULLNESS __s, const char* _Nonnull __fmt, ...)
George Burgess IV90242352018-02-06 12:51:31 -0800147 __printflike(2, 3) __warnattr_strict("sprintf is often misused; please use snprintf");
zijunzhaoe1833e52023-04-26 21:43:30 +0000148int vsprintf(char* __BIONIC_COMPLICATED_NULLNESS __s, const char* _Nonnull __fmt, va_list __args)
George Burgess IV90242352018-02-06 12:51:31 -0800149 __printflike(2, 0) __warnattr_strict("vsprintf is often misused; please use vsnprintf");
zijunzhao00a3dba2023-03-01 00:07:40 +0000150char* _Nullable tmpnam(char* _Nullable __s)
Elliott Hughes439ebbd2020-12-04 18:51:42 -0800151 __warnattr("tmpnam is unsafe, use mkstemp or tmpfile instead");
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700152#define P_tmpdir "/tmp/" /* deprecated */
zijunzhao00a3dba2023-03-01 00:07:40 +0000153char* _Nullable tempnam(const char* _Nullable __dir, const char* _Nullable __prefix)
George Burgess IV7cc779f2017-02-09 00:00:31 -0800154 __warnattr("tempnam is unsafe, use mkstemp or tmpfile instead");
Elliott Hughesd04c1832013-05-14 16:08:43 -0700155
Elliott Hughes05b675e2019-04-17 13:01:06 -0700156/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000157 * [rename(2)](https://man7.org/linux/man-pages/man2/rename.2.html) changes
Elliott Hughes05b675e2019-04-17 13:01:06 -0700158 * the name or location of a file.
159 *
160 * Returns 0 on success, and returns -1 and sets `errno` on failure.
161 */
zijunzhao00a3dba2023-03-01 00:07:40 +0000162int rename(const char* _Nonnull __old_path, const char* _Nonnull __new_path);
Elliott Hughes05b675e2019-04-17 13:01:06 -0700163
164/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000165 * [renameat(2)](https://man7.org/linux/man-pages/man2/renameat.2.html) changes
Elliott Hughes05b675e2019-04-17 13:01:06 -0700166 * the name or location of a file, interpreting relative paths using an fd.
167 *
168 * Returns 0 on success, and returns -1 and sets `errno` on failure.
169 */
zijunzhao00a3dba2023-03-01 00:07:40 +0000170int renameat(int __old_dir_fd, const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path);
Elliott Hughesd04c1832013-05-14 16:08:43 -0700171
Elliott Hughes05b675e2019-04-17 13:01:06 -0700172#if defined(__USE_GNU)
173
174/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000175 * Flag for [renameat2(2)](https://man7.org/linux/man-pages/man2/renameat2.2.html)
Elliott Hughes05b675e2019-04-17 13:01:06 -0700176 * to fail if the new path already exists.
177 */
178#define RENAME_NOREPLACE (1<<0)
179
180/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000181 * Flag for [renameat2(2)](https://man7.org/linux/man-pages/man2/renameat2.2.html)
Elliott Hughes05b675e2019-04-17 13:01:06 -0700182 * to atomically exchange the two paths.
183 */
184#define RENAME_EXCHANGE (1<<1)
185
186/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000187 * Flag for [renameat2(2)](https://man7.org/linux/man-pages/man2/renameat2.2.html)
Elliott Hughes05b675e2019-04-17 13:01:06 -0700188 * to create a union/overlay filesystem object.
189 */
190#define RENAME_WHITEOUT (1<<2)
191
192/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000193 * [renameat2(2)](https://man7.org/linux/man-pages/man2/renameat2.2.html) changes
Elliott Hughes05b675e2019-04-17 13:01:06 -0700194 * the name or location of a file, interpreting relative paths using an fd,
195 * with optional `RENAME_` flags.
196 *
197 * Returns 0 on success, and returns -1 and sets `errno` on failure.
198 */
Dan Albert02ce4012024-10-25 19:13:49 +0000199
200#if __BIONIC_AVAILABILITY_GUARD(30)
zijunzhao00a3dba2023-03-01 00:07:40 +0000201int renameat2(int __old_dir_fd, const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path, unsigned __flags) __INTRODUCED_IN(30);
Dan Albert02ce4012024-10-25 19:13:49 +0000202#endif /* __BIONIC_AVAILABILITY_GUARD(30) */
203
Elliott Hughes05b675e2019-04-17 13:01:06 -0700204
205#endif
206
zijunzhao00a3dba2023-03-01 00:07:40 +0000207int fseek(FILE* _Nonnull __fp, long __offset, int __whence);
Elliott Hughesb19df892024-09-06 14:27:41 +0000208__nodiscard long ftell(FILE* _Nonnull __fp);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800209
Elliott Hughes9c06d162023-10-04 23:36:14 +0000210/* See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md */
Elliott Hughes00fedf52017-07-05 15:23:50 -0700211#if defined(__USE_FILE_OFFSET64)
Dan Albert02ce4012024-10-25 19:13:49 +0000212
213#if __BIONIC_AVAILABILITY_GUARD(24)
zijunzhao00a3dba2023-03-01 00:07:40 +0000214int fgetpos(FILE* _Nonnull __fp, fpos_t* _Nonnull __pos) __RENAME(fgetpos64) __INTRODUCED_IN(24);
215int fsetpos(FILE* _Nonnull __fp, const fpos_t* _Nonnull __pos) __RENAME(fsetpos64) __INTRODUCED_IN(24);
216int fseeko(FILE* _Nonnull __fp, off_t __offset, int __whence) __RENAME(fseeko64) __INTRODUCED_IN(24);
Elliott Hughesb19df892024-09-06 14:27:41 +0000217__nodiscard off_t ftello(FILE* _Nonnull __fp) __RENAME(ftello64) __INTRODUCED_IN(24);
Dan Albert02ce4012024-10-25 19:13:49 +0000218#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
219
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800220# if defined(__USE_BSD)
zijunzhao00a3dba2023-03-01 00:07:40 +0000221/* If __read_fn and __write_fn are both nullptr, it will cause EINVAL */
Dan Albert02ce4012024-10-25 19:13:49 +0000222
223#if __BIONIC_AVAILABILITY_GUARD(24)
Elliott Hughesb19df892024-09-06 14:27:41 +0000224__nodiscard FILE* _Nullable funopen(const void* _Nullable __cookie,
zijunzhao00a3dba2023-03-01 00:07:40 +0000225 int (* __BIONIC_COMPLICATED_NULLNESS __read_fn)(void* _Nonnull, char* _Nonnull, int),
226 int (* __BIONIC_COMPLICATED_NULLNESS __write_fn)(void* _Nonnull, const char* _Nonnull, int),
227 fpos_t (* _Nullable __seek_fn)(void* _Nonnull, fpos_t, int),
228 int (* _Nullable __close_fn)(void* _Nonnull)) __RENAME(funopen64) __INTRODUCED_IN(24);
Dan Albert02ce4012024-10-25 19:13:49 +0000229#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
230
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800231# endif
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800232#else
zijunzhao00a3dba2023-03-01 00:07:40 +0000233int fgetpos(FILE* _Nonnull __fp, fpos_t* _Nonnull __pos);
234int fsetpos(FILE* _Nonnull __fp, const fpos_t* _Nonnull __pos);
235int fseeko(FILE* _Nonnull __fp, off_t __offset, int __whence);
Elliott Hughesb19df892024-09-06 14:27:41 +0000236__nodiscard off_t ftello(FILE* _Nonnull __fp);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800237# if defined(__USE_BSD)
zijunzhao00a3dba2023-03-01 00:07:40 +0000238/* If __read_fn and __write_fn are both nullptr, it will cause EINVAL */
Elliott Hughesb19df892024-09-06 14:27:41 +0000239__nodiscard FILE* _Nullable funopen(const void* _Nullable __cookie,
zijunzhao00a3dba2023-03-01 00:07:40 +0000240 int (* __BIONIC_COMPLICATED_NULLNESS __read_fn)(void* _Nonnull, char* _Nonnull, int),
241 int (* __BIONIC_COMPLICATED_NULLNESS __write_fn)(void* _Nonnull, const char* _Nonnull, int),
242 fpos_t (* _Nullable __seek_fn)(void* _Nonnull, fpos_t, int),
243 int (* _Nullable __close_fn)(void* _Nonnull));
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800244# endif
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800245#endif
Dan Albert02ce4012024-10-25 19:13:49 +0000246
247#if __BIONIC_AVAILABILITY_GUARD(24)
zijunzhao00a3dba2023-03-01 00:07:40 +0000248int fgetpos64(FILE* _Nonnull __fp, fpos64_t* _Nonnull __pos) __INTRODUCED_IN(24);
249int fsetpos64(FILE* _Nonnull __fp, const fpos64_t* _Nonnull __pos) __INTRODUCED_IN(24);
250int fseeko64(FILE* _Nonnull __fp, off64_t __offset, int __whence) __INTRODUCED_IN(24);
Elliott Hughesb19df892024-09-06 14:27:41 +0000251__nodiscard off64_t ftello64(FILE* _Nonnull __fp) __INTRODUCED_IN(24);
Dan Albert02ce4012024-10-25 19:13:49 +0000252#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
253
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800254#if defined(__USE_BSD)
zijunzhao00a3dba2023-03-01 00:07:40 +0000255/* If __read_fn and __write_fn are both nullptr, it will cause EINVAL */
Dan Albert02ce4012024-10-25 19:13:49 +0000256
257#if __BIONIC_AVAILABILITY_GUARD(24)
Elliott Hughesb19df892024-09-06 14:27:41 +0000258__nodiscard FILE* _Nullable funopen64(const void* _Nullable __cookie,
zijunzhao00a3dba2023-03-01 00:07:40 +0000259 int (* __BIONIC_COMPLICATED_NULLNESS __read_fn)(void* _Nonnull, char* _Nonnull, int),
260 int (* __BIONIC_COMPLICATED_NULLNESS __write_fn)(void* _Nonnull, const char* _Nonnull, int),
261 fpos64_t (* _Nullable __seek_fn)(void* _Nonnull, fpos64_t, int),
262 int (* _Nullable __close_fn)(void* _Nonnull)) __INTRODUCED_IN(24);
Dan Albert02ce4012024-10-25 19:13:49 +0000263#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
264
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800265#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800266
Elliott Hughesb19df892024-09-06 14:27:41 +0000267__nodiscard FILE* _Nullable fopen(const char* _Nonnull __path, const char* _Nonnull __mode);
Dan Albert02ce4012024-10-25 19:13:49 +0000268
269#if __BIONIC_AVAILABILITY_GUARD(24)
Elliott Hughesb19df892024-09-06 14:27:41 +0000270__nodiscard FILE* _Nullable fopen64(const char* _Nonnull __path, const char* _Nonnull __mode) __INTRODUCED_IN(24);
Dan Albert02ce4012024-10-25 19:13:49 +0000271#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
272
zijunzhao00a3dba2023-03-01 00:07:40 +0000273FILE* _Nullable freopen(const char* _Nullable __path, const char* _Nonnull __mode, FILE* _Nonnull __fp);
Dan Albert02ce4012024-10-25 19:13:49 +0000274
275#if __BIONIC_AVAILABILITY_GUARD(24)
zijunzhao00a3dba2023-03-01 00:07:40 +0000276FILE* _Nullable freopen64(const char* _Nullable __path, const char* _Nonnull __mode, FILE* _Nonnull __fp) __INTRODUCED_IN(24);
Dan Albert02ce4012024-10-25 19:13:49 +0000277#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
278
Elliott Hughesb19df892024-09-06 14:27:41 +0000279__nodiscard FILE* _Nullable tmpfile(void);
Dan Albert02ce4012024-10-25 19:13:49 +0000280
281#if __BIONIC_AVAILABILITY_GUARD(24)
Elliott Hughesb19df892024-09-06 14:27:41 +0000282__nodiscard FILE* _Nullable tmpfile64(void) __INTRODUCED_IN(24);
Dan Albert02ce4012024-10-25 19:13:49 +0000283#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
284
Elliott Hughesf226ee52016-02-03 11:24:28 -0800285
zijunzhaoe1833e52023-04-26 21:43:30 +0000286int snprintf(char* __BIONIC_COMPLICATED_NULLNESS __buf, size_t __size, const char* _Nonnull __fmt, ...) __printflike(3, 4);
zijunzhao00a3dba2023-03-01 00:07:40 +0000287int vfscanf(FILE* _Nonnull __fp, const char* _Nonnull __fmt, va_list __args) __scanflike(2, 0);
288int vscanf(const char* _Nonnull __fmt , va_list __args) __scanflike(1, 0);
zijunzhaoe1833e52023-04-26 21:43:30 +0000289int vsnprintf(char* __BIONIC_COMPLICATED_NULLNESS __buf, size_t __size, const char* _Nonnull __fmt, va_list __args) __printflike(3, 0);
zijunzhao00a3dba2023-03-01 00:07:40 +0000290int vsscanf(const char* _Nonnull __s, const char* _Nonnull __fmt, va_list __args) __scanflike(2, 0);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800291
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700292#define L_ctermid 1024 /* size for ctermid() */
Dan Albert02ce4012024-10-25 19:13:49 +0000293
294#if __BIONIC_AVAILABILITY_GUARD(26)
zijunzhao00a3dba2023-03-01 00:07:40 +0000295char* _Nonnull ctermid(char* _Nullable __buf) __INTRODUCED_IN(26);
Dan Albert02ce4012024-10-25 19:13:49 +0000296#endif /* __BIONIC_AVAILABILITY_GUARD(26) */
297
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800298
Elliott Hughesb19df892024-09-06 14:27:41 +0000299__nodiscard FILE* _Nullable fdopen(int __fd, const char* _Nonnull __mode);
300__nodiscard int fileno(FILE* _Nonnull __fp);
zijunzhao00a3dba2023-03-01 00:07:40 +0000301int pclose(FILE* _Nonnull __fp);
Elliott Hughesb19df892024-09-06 14:27:41 +0000302__nodiscard FILE* _Nullable popen(const char* _Nonnull __command, const char* _Nonnull __mode);
zijunzhao00a3dba2023-03-01 00:07:40 +0000303void flockfile(FILE* _Nonnull __fp);
304int ftrylockfile(FILE* _Nonnull __fp);
305void funlockfile(FILE* _Nonnull __fp);
Elliott Hughesb19df892024-09-06 14:27:41 +0000306__nodiscard int getc_unlocked(FILE* _Nonnull __fp);
307__nodiscard int getchar_unlocked(void);
zijunzhao00a3dba2023-03-01 00:07:40 +0000308int putc_unlocked(int __ch, FILE* _Nonnull __fp);
Elliott Hughesff26a162017-08-17 22:34:21 +0000309int putchar_unlocked(int __ch);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800310
Dan Albert95680c72024-10-23 21:11:28 +0000311
Dan Albert02ce4012024-10-25 19:13:49 +0000312#if __BIONIC_AVAILABILITY_GUARD(23)
313__nodiscard FILE* _Nullable fmemopen(void* _Nullable __buf, size_t __size, const char* _Nonnull __mode) __INTRODUCED_IN(23);
Elliott Hughesb19df892024-09-06 14:27:41 +0000314__nodiscard FILE* _Nullable open_memstream(char* _Nonnull * _Nonnull __ptr, size_t* _Nonnull __size_ptr) __INTRODUCED_IN(23);
Dan Albert02ce4012024-10-25 19:13:49 +0000315#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
316
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800317
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700318#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
zijunzhao00a3dba2023-03-01 00:07:40 +0000319int asprintf(char* _Nullable * _Nonnull __s_ptr, const char* _Nonnull __fmt, ...) __printflike(2, 3);
320char* _Nullable fgetln(FILE* _Nonnull __fp, size_t* _Nonnull __length_ptr);
321int fpurge(FILE* _Nonnull __fp);
322void setbuffer(FILE* _Nonnull __fp, char* _Nullable __buf, int __size);
323int setlinebuf(FILE* _Nonnull __fp);
324int vasprintf(char* _Nullable * _Nonnull __s_ptr, const char* _Nonnull __fmt, va_list __args) __printflike(2, 0);
Dan Albert02ce4012024-10-25 19:13:49 +0000325
326#if __BIONIC_AVAILABILITY_GUARD(23)
zijunzhao00a3dba2023-03-01 00:07:40 +0000327void clearerr_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Elliott Hughesb19df892024-09-06 14:27:41 +0000328__nodiscard int feof_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
329__nodiscard int ferror_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Dan Albert02ce4012024-10-25 19:13:49 +0000330#endif /* __BIONIC_AVAILABILITY_GUARD(23) */
331
332
333#if __BIONIC_AVAILABILITY_GUARD(24)
Elliott Hughesb19df892024-09-06 14:27:41 +0000334__nodiscard int fileno_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(24);
Dan Albert02ce4012024-10-25 19:13:49 +0000335#endif /* __BIONIC_AVAILABILITY_GUARD(24) */
336
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800337#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
338#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
Elliott Hughes37ad9592017-10-30 17:47:12 -0700339#endif
340
341#if defined(__USE_BSD)
Dan Albert02ce4012024-10-25 19:13:49 +0000342
343#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao00a3dba2023-03-01 00:07:40 +0000344int fflush_unlocked(FILE* _Nullable __fp) __INTRODUCED_IN(28);
Elliott Hughesb19df892024-09-06 14:27:41 +0000345__nodiscard int fgetc_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
zijunzhao00a3dba2023-03-01 00:07:40 +0000346int fputc_unlocked(int __ch, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
347size_t fread_unlocked(void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
348size_t fwrite_unlocked(const void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +0000349#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
350
Elliott Hughes37ad9592017-10-30 17:47:12 -0700351#endif
352
353#if defined(__USE_GNU)
Dan Albert02ce4012024-10-25 19:13:49 +0000354
355#if __BIONIC_AVAILABILITY_GUARD(28)
zijunzhao00a3dba2023-03-01 00:07:40 +0000356int fputs_unlocked(const char* _Nonnull __s, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
357char* _Nullable fgets_unlocked(char* _Nonnull __buf, int __size, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
Dan Albert02ce4012024-10-25 19:13:49 +0000358#endif /* __BIONIC_AVAILABILITY_GUARD(28) */
359
Elliott Hughes37ad9592017-10-30 17:47:12 -0700360#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800361
George Burgess IVb97049c2017-07-24 15:05:05 -0700362#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
363#include <bits/fortify/stdio.h>
364#endif
Nick Kralevichcffdf662012-06-11 15:50:57 -0700365
Dan Albert658727e2014-10-07 11:10:36 -0700366__END_DECLS
367
Elliott Hughesff26a162017-08-17 22:34:21 +0000368#endif