blob: d426a4a23eb64f346049b95881e78c3dbfeaa9fb [file] [log] [blame]
Elliott Hughes2b021e12014-08-19 17:00:33 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
Elliott Hughes462e90c2018-08-21 16:10:48 -070029#pragma once
30
31/**
32 * @file stdio_ext.h
33 * @brief Extra standard I/O functionality. See also `<stdio.h>`.
34 */
Elliott Hughes2b021e12014-08-19 17:00:33 -070035
36#include <sys/cdefs.h>
37#include <stdio.h>
38
Elliott Hughes2b021e12014-08-19 17:00:33 -070039__BEGIN_DECLS
40
Elliott Hughes462e90c2018-08-21 16:10:48 -070041/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000042 * [__fbufsize(3)](https://man7.org/linux/man-pages/man3/__fbufsize.3.html) returns the size of
Elliott Hughes462e90c2018-08-21 16:10:48 -070043 * the stream's buffer.
44 *
45 * Available since API level 23.
46 */
zijunzhao6b6d51e2023-02-27 22:23:42 +000047size_t __fbufsize(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Elliott Hughes462e90c2018-08-21 16:10:48 -070048
49/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000050 * [__freadable(3)](https://man7.org/linux/man-pages/man3/__freadable.3.html) returns non-zero if
Elliott Hughes462e90c2018-08-21 16:10:48 -070051 * the stream allows reading, 0 otherwise.
52 *
53 * Available since API level 23.
54 */
zijunzhao6b6d51e2023-02-27 22:23:42 +000055int __freadable(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Elliott Hughes462e90c2018-08-21 16:10:48 -070056
57/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000058 * [__freading(3)](https://man7.org/linux/man-pages/man3/__freading.3.html) returns non-zero if
Elliott Hughes462e90c2018-08-21 16:10:48 -070059 * the stream's last operation was a read, 0 otherwise.
60 *
61 * Available since API level 28.
62 */
zijunzhao6b6d51e2023-02-27 22:23:42 +000063int __freading(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
Elliott Hughes462e90c2018-08-21 16:10:48 -070064
65/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000066 * [__fwritable(3)](https://man7.org/linux/man-pages/man3/__fwritable.3.html) returns non-zero if
Elliott Hughes462e90c2018-08-21 16:10:48 -070067 * the stream allows writing, 0 otherwise.
68 *
69 * Available since API level 23.
70 */
zijunzhao6b6d51e2023-02-27 22:23:42 +000071int __fwritable(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Elliott Hughes462e90c2018-08-21 16:10:48 -070072
73/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000074 * [__fwriting(3)](https://man7.org/linux/man-pages/man3/__fwriting.3.html) returns non-zero if
Elliott Hughes462e90c2018-08-21 16:10:48 -070075 * the stream's last operation was a write, 0 otherwise.
76 *
77 * Available since API level 28.
78 */
zijunzhao6b6d51e2023-02-27 22:23:42 +000079int __fwriting(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
Elliott Hughes462e90c2018-08-21 16:10:48 -070080
81/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000082 * [__flbf(3)](https://man7.org/linux/man-pages/man3/__flbf.3.html) returns non-zero if
Elliott Hughes462e90c2018-08-21 16:10:48 -070083 * the stream is line-buffered, 0 otherwise.
84 *
85 * Available since API level 23.
86 */
zijunzhao6b6d51e2023-02-27 22:23:42 +000087int __flbf(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Elliott Hughes462e90c2018-08-21 16:10:48 -070088
89/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000090 * [__fpurge(3)](https://man7.org/linux/man-pages/man3/__fpurge.3.html) discards the contents of
Elliott Hughes462e90c2018-08-21 16:10:48 -070091 * the stream's buffer.
Elliott Hughes462e90c2018-08-21 16:10:48 -070092 */
Elliott Hughes00a2a6f2024-08-12 21:32:07 +000093void __fpurge(FILE* _Nonnull __fp) __RENAME(fpurge);
Elliott Hughes462e90c2018-08-21 16:10:48 -070094
95/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000096 * [__fpending(3)](https://man7.org/linux/man-pages/man3/__fpending.3.html) returns the number of
Elliott Hughes82be76b2022-09-22 23:47:42 +000097 * bytes in the output buffer. See __freadahead() for the input buffer.
Elliott Hughes462e90c2018-08-21 16:10:48 -070098 *
99 * Available since API level 23.
100 */
zijunzhao6b6d51e2023-02-27 22:23:42 +0000101size_t __fpending(FILE* _Nonnull __fp) __INTRODUCED_IN(23);
Elliott Hughes462e90c2018-08-21 16:10:48 -0700102
103/**
Elliott Hughes82be76b2022-09-22 23:47:42 +0000104 * __freadahead(3) returns the number of bytes in the input buffer.
105 * See __fpending() for the output buffer.
106 *
107 * Available since API level 34.
108 */
zijunzhao6b6d51e2023-02-27 22:23:42 +0000109size_t __freadahead(FILE* _Nonnull __fp) __INTRODUCED_IN(34);
Elliott Hughes82be76b2022-09-22 23:47:42 +0000110
111/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000112 * [_flushlbf(3)](https://man7.org/linux/man-pages/man3/_flushlbf.3.html) flushes all
Elliott Hughes462e90c2018-08-21 16:10:48 -0700113 * line-buffered streams.
114 *
115 * Available since API level 23.
116 */
Josh Gao14adff12016-04-29 12:00:55 -0700117void _flushlbf(void) __INTRODUCED_IN(23);
Elliott Hughesfaa74342017-08-11 17:34:44 -0700118
Elliott Hughes462e90c2018-08-21 16:10:48 -0700119/**
120 * `__fseterr` sets the
121 * stream's error flag (as tested by ferror() and cleared by fclearerr()).
122 *
123 * Available since API level 28.
124 */
zijunzhao6b6d51e2023-02-27 22:23:42 +0000125void __fseterr(FILE* _Nonnull __fp) __INTRODUCED_IN(28);
Elliott Hughes45785262018-02-14 15:21:45 -0800126
Elliott Hughes462e90c2018-08-21 16:10:48 -0700127/** __fsetlocking() constant to query locking type. */
Elliott Hughesfaa74342017-08-11 17:34:44 -0700128#define FSETLOCKING_QUERY 0
Elliott Hughes462e90c2018-08-21 16:10:48 -0700129/** __fsetlocking() constant to set locking to be maintained by stdio. */
Elliott Hughesfaa74342017-08-11 17:34:44 -0700130#define FSETLOCKING_INTERNAL 1
Elliott Hughes462e90c2018-08-21 16:10:48 -0700131/** __fsetlocking() constant to set locking to be maintained by the caller. */
Elliott Hughesfaa74342017-08-11 17:34:44 -0700132#define FSETLOCKING_BYCALLER 2
Elliott Hughes462e90c2018-08-21 16:10:48 -0700133
134/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000135 * [__fsetlocking(3)](https://man7.org/linux/man-pages/man3/__fsetlocking.3.html) sets the
Elliott Hughes462e90c2018-08-21 16:10:48 -0700136 * stream's locking mode to one of the `FSETLOCKING_` types.
137 *
138 * Returns the current locking style, `FSETLOCKING_INTERNAL` or `FSETLOCKING_BYCALLER`.
139 *
140 * Available since API level 23.
141 */
zijunzhao6b6d51e2023-02-27 22:23:42 +0000142int __fsetlocking(FILE* _Nonnull __fp, int __type) __INTRODUCED_IN(23);
Elliott Hughes2b021e12014-08-19 17:00:33 -0700143
144__END_DECLS