Add __freadahead.
At the time I added <stdio_ext.h>, I just added what was on the man
page (which matched glibc), not realizing that musl and glibc had
slightly different functionality in their headers.
The toybox maintainer came up with a legitimate use case for this, for
which there is no portable workaround, so I'm adding it here. I'm not
adding the other functions that are in musl but not glibc for lack of a
motivating use case.
Bug: http://lists.landley.net/htdig.cgi/toybox-landley.net/2022-April/020864.html
Test: treehugger
Change-Id: I073baa86ff0271064d4e2f20a584d38787ead6b0
diff --git a/tests/stdio_ext_test.cpp b/tests/stdio_ext_test.cpp
index fce600a..dce1a66 100644
--- a/tests/stdio_ext_test.cpp
+++ b/tests/stdio_ext_test.cpp
@@ -78,6 +78,24 @@
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();