Merge "Add __freadahead."

This commit is contained in:
Elliott Hughes 2022-09-27 18:47:34 +00:00 committed by Gerrit Code Review
commit 305399264b
5 changed files with 35 additions and 1 deletions

View File

@ -54,6 +54,7 @@ Current libc symbols: https://android.googlesource.com/platform/bionic/+/master/
New libc functions in U (API level 34):
* `close_range` and `copy_file_range` (Linux-specific GNU extensions).
* `memset_explicit` in <string.h> (C23 addition).
* `__freadahead` in <stdio_ext.h> (in musl but not glibc).
New libc behavior in U (API level 34):
* Support for `%b` and `%B` in the printf/wprintf family, `%b` in the

View File

@ -96,12 +96,20 @@ void __fpurge(FILE* __fp) __INTRODUCED_IN(23);
/**
* [__fpending(3)](http://man7.org/linux/man-pages/man3/__fpending.3.html) returns the number of
* bytes in the output buffer.
* bytes in the output buffer. See __freadahead() for the input buffer.
*
* Available since API level 23.
*/
size_t __fpending(FILE* __fp) __INTRODUCED_IN(23);
/**
* __freadahead(3) returns the number of bytes in the input buffer.
* See __fpending() for the output buffer.
*
* Available since API level 34.
*/
size_t __freadahead(FILE* __fp) __INTRODUCED_IN(34);
/**
* [_flushlbf(3)](http://man7.org/linux/man-pages/man3/_flushlbf.3.html) flushes all
* line-buffered streams.

View File

@ -1578,6 +1578,7 @@ LIBC_T { # introduced=Tiramisu
LIBC_U { # introduced=UpsideDownCake
global:
__freadahead;
close_range;
copy_file_range;
memset_explicit;

View File

@ -67,6 +67,12 @@ size_t __fpending(FILE* fp) {
return fp->_p - fp->_bf._base;
}
size_t __freadahead(FILE* fp) {
// Normally _r is the amount of input already available.
// When there's ungetc() data, _r counts that and _ur is the previous _r.
return fp->_r + (HASUB(fp) ? fp->_ur : 0);
}
void _flushlbf() {
// If we flush all streams, we know we've flushed all the line-buffered streams.
fflush(nullptr);

View File

@ -78,6 +78,24 @@ TEST(stdio_ext, __fpending) {
fclose(fp);
}
TEST(stdio_ext, __freadahead) {
#if defined(__GLIBC__)
GTEST_SKIP() << "glibc doesn't have __freadahead";
#else
FILE* fp = tmpfile();
ASSERT_NE(EOF, fputs("hello", fp));
rewind(fp);
ASSERT_EQ('h', fgetc(fp));
ASSERT_EQ(4u, __freadahead(fp));
ASSERT_EQ('H', ungetc('H', fp));
ASSERT_EQ(5u, __freadahead(fp));
fclose(fp);
#endif
}
TEST(stdio_ext, __fpurge) {
FILE* fp = tmpfile();