Elliott Hughes | 2b021e1 | 2014-08-19 17:00:33 -0700 | [diff] [blame] | 1 | /* |
| 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 Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 29 | #pragma once |
| 30 | |
| 31 | /** |
| 32 | * @file stdio_ext.h |
| 33 | * @brief Extra standard I/O functionality. See also `<stdio.h>`. |
| 34 | */ |
Elliott Hughes | 2b021e1 | 2014-08-19 17:00:33 -0700 | [diff] [blame] | 35 | |
| 36 | #include <sys/cdefs.h> |
| 37 | #include <stdio.h> |
| 38 | |
Elliott Hughes | 2b021e1 | 2014-08-19 17:00:33 -0700 | [diff] [blame] | 39 | __BEGIN_DECLS |
| 40 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 41 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 42 | * [__fbufsize(3)](https://man7.org/linux/man-pages/man3/__fbufsize.3.html) returns the size of |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 43 | * the stream's buffer. |
| 44 | * |
| 45 | * Available since API level 23. |
| 46 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 47 | |
| 48 | #if __BIONIC_AVAILABILITY_GUARD(23) |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 49 | size_t __fbufsize(FILE* _Nonnull __fp) __INTRODUCED_IN(23); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 52 | * [__freadable(3)](https://man7.org/linux/man-pages/man3/__freadable.3.html) returns non-zero if |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 53 | * the stream allows reading, 0 otherwise. |
| 54 | * |
| 55 | * Available since API level 23. |
| 56 | */ |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 57 | int __freadable(FILE* _Nonnull __fp) __INTRODUCED_IN(23); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 58 | #endif /* __BIONIC_AVAILABILITY_GUARD(23) */ |
| 59 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 62 | * [__freading(3)](https://man7.org/linux/man-pages/man3/__freading.3.html) returns non-zero if |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 63 | * the stream's last operation was a read, 0 otherwise. |
| 64 | * |
| 65 | * Available since API level 28. |
| 66 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 67 | |
| 68 | #if __BIONIC_AVAILABILITY_GUARD(28) |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 69 | int __freading(FILE* _Nonnull __fp) __INTRODUCED_IN(28); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 70 | #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ |
| 71 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 74 | * [__fwritable(3)](https://man7.org/linux/man-pages/man3/__fwritable.3.html) returns non-zero if |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 75 | * the stream allows writing, 0 otherwise. |
| 76 | * |
| 77 | * Available since API level 23. |
| 78 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 79 | |
| 80 | #if __BIONIC_AVAILABILITY_GUARD(23) |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 81 | int __fwritable(FILE* _Nonnull __fp) __INTRODUCED_IN(23); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 82 | #endif /* __BIONIC_AVAILABILITY_GUARD(23) */ |
| 83 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 86 | * [__fwriting(3)](https://man7.org/linux/man-pages/man3/__fwriting.3.html) returns non-zero if |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 87 | * the stream's last operation was a write, 0 otherwise. |
| 88 | * |
| 89 | * Available since API level 28. |
| 90 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 91 | |
| 92 | #if __BIONIC_AVAILABILITY_GUARD(28) |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 93 | int __fwriting(FILE* _Nonnull __fp) __INTRODUCED_IN(28); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 94 | #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ |
| 95 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 98 | * [__flbf(3)](https://man7.org/linux/man-pages/man3/__flbf.3.html) returns non-zero if |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 99 | * the stream is line-buffered, 0 otherwise. |
| 100 | * |
| 101 | * Available since API level 23. |
| 102 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 103 | |
| 104 | #if __BIONIC_AVAILABILITY_GUARD(23) |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 105 | int __flbf(FILE* _Nonnull __fp) __INTRODUCED_IN(23); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 106 | #endif /* __BIONIC_AVAILABILITY_GUARD(23) */ |
| 107 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 110 | * [__fpurge(3)](https://man7.org/linux/man-pages/man3/__fpurge.3.html) discards the contents of |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 111 | * the stream's buffer. |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 112 | */ |
Elliott Hughes | 00a2a6f | 2024-08-12 21:32:07 +0000 | [diff] [blame] | 113 | void __fpurge(FILE* _Nonnull __fp) __RENAME(fpurge); |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 116 | * [__fpending(3)](https://man7.org/linux/man-pages/man3/__fpending.3.html) returns the number of |
Elliott Hughes | 82be76b | 2022-09-22 23:47:42 +0000 | [diff] [blame] | 117 | * bytes in the output buffer. See __freadahead() for the input buffer. |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 118 | * |
| 119 | * Available since API level 23. |
| 120 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 121 | |
| 122 | #if __BIONIC_AVAILABILITY_GUARD(23) |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 123 | size_t __fpending(FILE* _Nonnull __fp) __INTRODUCED_IN(23); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 124 | #endif /* __BIONIC_AVAILABILITY_GUARD(23) */ |
| 125 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 126 | |
| 127 | /** |
Elliott Hughes | 82be76b | 2022-09-22 23:47:42 +0000 | [diff] [blame] | 128 | * __freadahead(3) returns the number of bytes in the input buffer. |
| 129 | * See __fpending() for the output buffer. |
| 130 | * |
| 131 | * Available since API level 34. |
| 132 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 133 | |
| 134 | #if __BIONIC_AVAILABILITY_GUARD(34) |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 135 | size_t __freadahead(FILE* _Nonnull __fp) __INTRODUCED_IN(34); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 136 | #endif /* __BIONIC_AVAILABILITY_GUARD(34) */ |
| 137 | |
Elliott Hughes | 82be76b | 2022-09-22 23:47:42 +0000 | [diff] [blame] | 138 | |
| 139 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 140 | * [_flushlbf(3)](https://man7.org/linux/man-pages/man3/_flushlbf.3.html) flushes all |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 141 | * line-buffered streams. |
| 142 | * |
| 143 | * Available since API level 23. |
| 144 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 145 | |
| 146 | #if __BIONIC_AVAILABILITY_GUARD(23) |
Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 147 | void _flushlbf(void) __INTRODUCED_IN(23); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 148 | #endif /* __BIONIC_AVAILABILITY_GUARD(23) */ |
| 149 | |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 150 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 151 | /** |
| 152 | * `__fseterr` sets the |
| 153 | * stream's error flag (as tested by ferror() and cleared by fclearerr()). |
| 154 | * |
| 155 | * Available since API level 28. |
| 156 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 157 | |
| 158 | #if __BIONIC_AVAILABILITY_GUARD(28) |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 159 | void __fseterr(FILE* _Nonnull __fp) __INTRODUCED_IN(28); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 160 | #endif /* __BIONIC_AVAILABILITY_GUARD(28) */ |
| 161 | |
Elliott Hughes | 4578526 | 2018-02-14 15:21:45 -0800 | [diff] [blame] | 162 | |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 163 | /** __fsetlocking() constant to query locking type. */ |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 164 | #define FSETLOCKING_QUERY 0 |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 165 | /** __fsetlocking() constant to set locking to be maintained by stdio. */ |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 166 | #define FSETLOCKING_INTERNAL 1 |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 167 | /** __fsetlocking() constant to set locking to be maintained by the caller. */ |
Elliott Hughes | faa7434 | 2017-08-11 17:34:44 -0700 | [diff] [blame] | 168 | #define FSETLOCKING_BYCALLER 2 |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 169 | |
| 170 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 171 | * [__fsetlocking(3)](https://man7.org/linux/man-pages/man3/__fsetlocking.3.html) sets the |
Elliott Hughes | 462e90c | 2018-08-21 16:10:48 -0700 | [diff] [blame] | 172 | * stream's locking mode to one of the `FSETLOCKING_` types. |
| 173 | * |
| 174 | * Returns the current locking style, `FSETLOCKING_INTERNAL` or `FSETLOCKING_BYCALLER`. |
| 175 | * |
| 176 | * Available since API level 23. |
| 177 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 178 | |
| 179 | #if __BIONIC_AVAILABILITY_GUARD(23) |
zijunzhao | 6b6d51e | 2023-02-27 22:23:42 +0000 | [diff] [blame] | 180 | int __fsetlocking(FILE* _Nonnull __fp, int __type) __INTRODUCED_IN(23); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame^] | 181 | #endif /* __BIONIC_AVAILABILITY_GUARD(23) */ |
| 182 | |
Elliott Hughes | 2b021e1 | 2014-08-19 17:00:33 -0700 | [diff] [blame] | 183 | |
| 184 | __END_DECLS |