blob: 4912c0aec8947f85cf78d011aae6a4b14b8fd224 [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 */
zijunzhao00a3dba2023-03-01 00:07:40 +0000199int renameat2(int __old_dir_fd, const char* _Nonnull __old_path, int __new_dir_fd, const char* _Nonnull __new_path, unsigned __flags) __INTRODUCED_IN(30);
Elliott Hughes05b675e2019-04-17 13:01:06 -0700200
201#endif
202
zijunzhao00a3dba2023-03-01 00:07:40 +0000203int fseek(FILE* _Nonnull __fp, long __offset, int __whence);
Elliott Hughesb19df892024-09-06 14:27:41 +0000204__nodiscard long ftell(FILE* _Nonnull __fp);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800205
Elliott Hughes9c06d162023-10-04 23:36:14 +0000206/* See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md */
Elliott Hughes00fedf52017-07-05 15:23:50 -0700207#if defined(__USE_FILE_OFFSET64)
zijunzhao00a3dba2023-03-01 00:07:40 +0000208int fgetpos(FILE* _Nonnull __fp, fpos_t* _Nonnull __pos) __RENAME(fgetpos64) __INTRODUCED_IN(24);
209int fsetpos(FILE* _Nonnull __fp, const fpos_t* _Nonnull __pos) __RENAME(fsetpos64) __INTRODUCED_IN(24);
210int fseeko(FILE* _Nonnull __fp, off_t __offset, int __whence) __RENAME(fseeko64) __INTRODUCED_IN(24);
Elliott Hughesb19df892024-09-06 14:27:41 +0000211__nodiscard off_t ftello(FILE* _Nonnull __fp) __RENAME(ftello64) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800212# if defined(__USE_BSD)
zijunzhao00a3dba2023-03-01 00:07:40 +0000213/* If __read_fn and __write_fn are both nullptr, it will cause EINVAL */
Elliott Hughesb19df892024-09-06 14:27:41 +0000214__nodiscard FILE* _Nullable funopen(const void* _Nullable __cookie,
zijunzhao00a3dba2023-03-01 00:07:40 +0000215 int (* __BIONIC_COMPLICATED_NULLNESS __read_fn)(void* _Nonnull, char* _Nonnull, int),
216 int (* __BIONIC_COMPLICATED_NULLNESS __write_fn)(void* _Nonnull, const char* _Nonnull, int),
217 fpos_t (* _Nullable __seek_fn)(void* _Nonnull, fpos_t, int),
218 int (* _Nullable __close_fn)(void* _Nonnull)) __RENAME(funopen64) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800219# endif
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800220#else
zijunzhao00a3dba2023-03-01 00:07:40 +0000221int fgetpos(FILE* _Nonnull __fp, fpos_t* _Nonnull __pos);
222int fsetpos(FILE* _Nonnull __fp, const fpos_t* _Nonnull __pos);
223int fseeko(FILE* _Nonnull __fp, off_t __offset, int __whence);
Elliott Hughesb19df892024-09-06 14:27:41 +0000224__nodiscard off_t ftello(FILE* _Nonnull __fp);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800225# if defined(__USE_BSD)
zijunzhao00a3dba2023-03-01 00:07:40 +0000226/* If __read_fn and __write_fn are both nullptr, it will cause EINVAL */
Elliott Hughesb19df892024-09-06 14:27:41 +0000227__nodiscard FILE* _Nullable funopen(const void* _Nullable __cookie,
zijunzhao00a3dba2023-03-01 00:07:40 +0000228 int (* __BIONIC_COMPLICATED_NULLNESS __read_fn)(void* _Nonnull, char* _Nonnull, int),
229 int (* __BIONIC_COMPLICATED_NULLNESS __write_fn)(void* _Nonnull, const char* _Nonnull, int),
230 fpos_t (* _Nullable __seek_fn)(void* _Nonnull, fpos_t, int),
231 int (* _Nullable __close_fn)(void* _Nonnull));
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800232# endif
Elliott Hughes68dc20d2015-02-06 22:28:49 -0800233#endif
zijunzhao00a3dba2023-03-01 00:07:40 +0000234int fgetpos64(FILE* _Nonnull __fp, fpos64_t* _Nonnull __pos) __INTRODUCED_IN(24);
235int fsetpos64(FILE* _Nonnull __fp, const fpos64_t* _Nonnull __pos) __INTRODUCED_IN(24);
236int fseeko64(FILE* _Nonnull __fp, off64_t __offset, int __whence) __INTRODUCED_IN(24);
Elliott Hughesb19df892024-09-06 14:27:41 +0000237__nodiscard off64_t ftello64(FILE* _Nonnull __fp) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800238#if defined(__USE_BSD)
zijunzhao00a3dba2023-03-01 00:07:40 +0000239/* If __read_fn and __write_fn are both nullptr, it will cause EINVAL */
Elliott Hughesb19df892024-09-06 14:27:41 +0000240__nodiscard FILE* _Nullable funopen64(const void* _Nullable __cookie,
zijunzhao00a3dba2023-03-01 00:07:40 +0000241 int (* __BIONIC_COMPLICATED_NULLNESS __read_fn)(void* _Nonnull, char* _Nonnull, int),
242 int (* __BIONIC_COMPLICATED_NULLNESS __write_fn)(void* _Nonnull, const char* _Nonnull, int),
243 fpos64_t (* _Nullable __seek_fn)(void* _Nonnull, fpos64_t, int),
244 int (* _Nullable __close_fn)(void* _Nonnull)) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800245#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800246
Elliott Hughesb19df892024-09-06 14:27:41 +0000247__nodiscard FILE* _Nullable fopen(const char* _Nonnull __path, const char* _Nonnull __mode);
248__nodiscard FILE* _Nullable fopen64(const char* _Nonnull __path, const char* _Nonnull __mode) __INTRODUCED_IN(24);
zijunzhao00a3dba2023-03-01 00:07:40 +0000249FILE* _Nullable freopen(const char* _Nullable __path, const char* _Nonnull __mode, FILE* _Nonnull __fp);
250FILE* _Nullable freopen64(const char* _Nullable __path, const char* _Nonnull __mode, FILE* _Nonnull __fp) __INTRODUCED_IN(24);
Elliott Hughesb19df892024-09-06 14:27:41 +0000251__nodiscard FILE* _Nullable tmpfile(void);
252__nodiscard FILE* _Nullable tmpfile64(void) __INTRODUCED_IN(24);
Elliott Hughesf226ee52016-02-03 11:24:28 -0800253
zijunzhaoe1833e52023-04-26 21:43:30 +0000254int snprintf(char* __BIONIC_COMPLICATED_NULLNESS __buf, size_t __size, const char* _Nonnull __fmt, ...) __printflike(3, 4);
zijunzhao00a3dba2023-03-01 00:07:40 +0000255int vfscanf(FILE* _Nonnull __fp, const char* _Nonnull __fmt, va_list __args) __scanflike(2, 0);
256int vscanf(const char* _Nonnull __fmt , va_list __args) __scanflike(1, 0);
zijunzhaoe1833e52023-04-26 21:43:30 +0000257int 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 +0000258int 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 -0800259
Elliott Hughes3ba55f82016-06-08 18:11:23 -0700260#define L_ctermid 1024 /* size for ctermid() */
zijunzhao00a3dba2023-03-01 00:07:40 +0000261char* _Nonnull ctermid(char* _Nullable __buf) __INTRODUCED_IN(26);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800262
Elliott Hughesb19df892024-09-06 14:27:41 +0000263__nodiscard FILE* _Nullable fdopen(int __fd, const char* _Nonnull __mode);
264__nodiscard int fileno(FILE* _Nonnull __fp);
zijunzhao00a3dba2023-03-01 00:07:40 +0000265int pclose(FILE* _Nonnull __fp);
Elliott Hughesb19df892024-09-06 14:27:41 +0000266__nodiscard FILE* _Nullable popen(const char* _Nonnull __command, const char* _Nonnull __mode);
zijunzhao00a3dba2023-03-01 00:07:40 +0000267void flockfile(FILE* _Nonnull __fp);
268int ftrylockfile(FILE* _Nonnull __fp);
269void funlockfile(FILE* _Nonnull __fp);
Elliott Hughesb19df892024-09-06 14:27:41 +0000270__nodiscard int getc_unlocked(FILE* _Nonnull __fp);
271__nodiscard int getchar_unlocked(void);
zijunzhao00a3dba2023-03-01 00:07:40 +0000272int putc_unlocked(int __ch, FILE* _Nonnull __fp);
Elliott Hughesff26a162017-08-17 22:34:21 +0000273int putchar_unlocked(int __ch);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800274
Dan Albert95680c72024-10-23 21:11:28 +0000275// This causes issues with a polyfill in libconfuse
276// https://github.com/android/ndk/issues/2081
277#if __ANDROID_API__ >= 23
Elliott Hughesb19df892024-09-06 14:27:41 +0000278__nodiscard FILE* _Nullable fmemopen(void* _Nullable __buf, size_t __size, const char* _Nonnull __mode) __INTRODUCED_IN(23);
Dan Albert95680c72024-10-23 21:11:28 +0000279#endif
280
Elliott Hughesb19df892024-09-06 14:27:41 +0000281__nodiscard FILE* _Nullable open_memstream(char* _Nonnull * _Nonnull __ptr, size_t* _Nonnull __size_ptr) __INTRODUCED_IN(23);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800282
Elliott Hughes9c8d7112016-06-13 13:23:42 -0700283#if defined(__USE_BSD) || defined(__BIONIC__) /* Historically bionic exposed these. */
zijunzhao00a3dba2023-03-01 00:07:40 +0000284int asprintf(char* _Nullable * _Nonnull __s_ptr, const char* _Nonnull __fmt, ...) __printflike(2, 3);
285char* _Nullable fgetln(FILE* _Nonnull __fp, size_t* _Nonnull __length_ptr);
286int fpurge(FILE* _Nonnull __fp);
287void setbuffer(FILE* _Nonnull __fp, char* _Nullable __buf, int __size);
288int setlinebuf(FILE* _Nonnull __fp);
289int vasprintf(char* _Nullable * _Nonnull __s_ptr, const char* _Nonnull __fmt, va_list __args) __printflike(2, 0);
290void clearerr_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Elliott Hughesb19df892024-09-06 14:27:41 +0000291__nodiscard int feof_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
292__nodiscard int ferror_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
293__nodiscard int fileno_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(24);
Elliott Hughes03e65eb2016-01-26 14:13:04 -0800294#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
295#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
Elliott Hughes37ad9592017-10-30 17:47:12 -0700296#endif
297
298#if defined(__USE_BSD)
zijunzhao00a3dba2023-03-01 00:07:40 +0000299int fflush_unlocked(FILE* _Nullable __fp) __INTRODUCED_IN(28);
Elliott Hughesb19df892024-09-06 14:27:41 +0000300__nodiscard int fgetc_unlocked(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
zijunzhao00a3dba2023-03-01 00:07:40 +0000301int fputc_unlocked(int __ch, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
302size_t fread_unlocked(void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
303size_t fwrite_unlocked(const void* _Nonnull __buf, size_t __size, size_t __count, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
Elliott Hughes37ad9592017-10-30 17:47:12 -0700304#endif
305
306#if defined(__USE_GNU)
zijunzhao00a3dba2023-03-01 00:07:40 +0000307int fputs_unlocked(const char* _Nonnull __s, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
308char* _Nullable fgets_unlocked(char* _Nonnull __buf, int __size, FILE* _Nonnull __fp) __INTRODUCED_IN(28);
Elliott Hughes37ad9592017-10-30 17:47:12 -0700309#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800310
George Burgess IVb97049c2017-07-24 15:05:05 -0700311#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
312#include <bits/fortify/stdio.h>
313#endif
Nick Kralevichcffdf662012-06-11 15:50:57 -0700314
Dan Albert658727e2014-10-07 11:10:36 -0700315__END_DECLS
316
Elliott Hughesff26a162017-08-17 22:34:21 +0000317#endif