From 457852666cb870a844df016962fac487cb5e7559 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 14 Feb 2018 15:21:45 -0800 Subject: [PATCH] Add __fseterr. Trivial, obvious counterpart to the standard ferror(3) and clearerr(3), and lets us build bison out of the box. Bug: http://b/64273806 Test: ran tests Change-Id: I20affabddb71210051165c41e86adfe5ae04f77f --- libc/include/stdio_ext.h | 2 ++ libc/libc.arm.map | 1 + libc/libc.arm64.map | 1 + libc/libc.map.txt | 1 + libc/libc.mips.map | 1 + libc/libc.mips64.map | 1 + libc/libc.x86.map | 1 + libc/libc.x86_64.map | 1 + libc/stdio/stdio_ext.cpp | 4 ++++ tests/stdio_ext_test.cpp | 16 ++++++++++++++++ 10 files changed, 29 insertions(+) diff --git a/libc/include/stdio_ext.h b/libc/include/stdio_ext.h index 2f0f438e0..b8aa68dbd 100644 --- a/libc/include/stdio_ext.h +++ b/libc/include/stdio_ext.h @@ -45,6 +45,8 @@ void __fpurge(FILE* __fp) __INTRODUCED_IN(23); size_t __fpending(FILE* __fp) __INTRODUCED_IN(23); void _flushlbf(void) __INTRODUCED_IN(23); +void __fseterr(FILE* __fp) __INTRODUCED_IN(28); + #define FSETLOCKING_QUERY 0 #define FSETLOCKING_INTERNAL 1 #define FSETLOCKING_BYCALLER 2 diff --git a/libc/libc.arm.map b/libc/libc.arm.map index 4586fdacd..dc0eb9397 100644 --- a/libc/libc.arm.map +++ b/libc/libc.arm.map @@ -1322,6 +1322,7 @@ LIBC_P { # introduced=P global: __freading; __free_hook; + __fseterr; __fwriting; __malloc_hook; __memalign_hook; diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map index 75436ff0c..fdae8f11f 100644 --- a/libc/libc.arm64.map +++ b/libc/libc.arm64.map @@ -1242,6 +1242,7 @@ LIBC_P { # introduced=P global: __freading; __free_hook; + __fseterr; __fwriting; __malloc_hook; __memalign_hook; diff --git a/libc/libc.map.txt b/libc/libc.map.txt index a8a52c302..07241d5e4 100644 --- a/libc/libc.map.txt +++ b/libc/libc.map.txt @@ -1347,6 +1347,7 @@ LIBC_P { # introduced=P global: __freading; __free_hook; + __fseterr; __fwriting; __malloc_hook; __memalign_hook; diff --git a/libc/libc.mips.map b/libc/libc.mips.map index 584807e39..bbd599afd 100644 --- a/libc/libc.mips.map +++ b/libc/libc.mips.map @@ -1306,6 +1306,7 @@ LIBC_P { # introduced=P global: __freading; __free_hook; + __fseterr; __fwriting; __malloc_hook; __memalign_hook; diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map index 75436ff0c..fdae8f11f 100644 --- a/libc/libc.mips64.map +++ b/libc/libc.mips64.map @@ -1242,6 +1242,7 @@ LIBC_P { # introduced=P global: __freading; __free_hook; + __fseterr; __fwriting; __malloc_hook; __memalign_hook; diff --git a/libc/libc.x86.map b/libc/libc.x86.map index 4498d6d21..6e9acc025 100644 --- a/libc/libc.x86.map +++ b/libc/libc.x86.map @@ -1304,6 +1304,7 @@ LIBC_P { # introduced=P global: __freading; __free_hook; + __fseterr; __fwriting; __malloc_hook; __memalign_hook; diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map index 75436ff0c..fdae8f11f 100644 --- a/libc/libc.x86_64.map +++ b/libc/libc.x86_64.map @@ -1242,6 +1242,7 @@ LIBC_P { # introduced=P global: __freading; __free_hook; + __fseterr; __fwriting; __malloc_hook; __memalign_hook; diff --git a/libc/stdio/stdio_ext.cpp b/libc/stdio/stdio_ext.cpp index 8cf4f4b3d..e17b62a05 100644 --- a/libc/stdio/stdio_ext.cpp +++ b/libc/stdio/stdio_ext.cpp @@ -72,6 +72,10 @@ void _flushlbf() { fflush(NULL); } +void __fseterr(FILE* fp) { + fp->_flags |= __SERR; +} + int __fsetlocking(FILE* fp, int type) { int old_state = _EXT(fp)->_caller_handles_locking ? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL; if (type == FSETLOCKING_QUERY) { diff --git a/tests/stdio_ext_test.cpp b/tests/stdio_ext_test.cpp index 128e25558..849bf0bc1 100644 --- a/tests/stdio_ext_test.cpp +++ b/tests/stdio_ext_test.cpp @@ -190,6 +190,22 @@ TEST(stdio_ext, __freading__fwriting) { } } +TEST(stdio_ext, __fseterr) { +#if defined(__GLIBC__) + GTEST_LOG_(INFO) << "glibc doesn't have __fseterr, but gnulib will use it"; +#else + FILE* fp = fopen("/dev/null", "w"); + + ASSERT_FALSE(ferror(fp)); + __fseterr(fp); + ASSERT_TRUE(ferror(fp)); + clearerr(fp); + ASSERT_FALSE(ferror(fp)); + + fclose(fp); +#endif +} + TEST(stdio_ext, __fsetlocking) { FILE* fp = fopen("/proc/version", "r"); ASSERT_EQ(FSETLOCKING_INTERNAL, __fsetlocking(fp, FSETLOCKING_QUERY));