Merge <stdio_ext.h>'s __fpurge() with <stdio.h>'s fpurge().
Found going down the list of single-instruction functions in libc.so, but this also lets us get rid of an __INTRODUCED_IN().
ELF aliases can only be used in the same translation unit as the real
definition, which requires tidying up the fpurge() implementation a bit.
Change-Id: Ia3254fb4b7a3bfc8c6287adad67f0d2d5e5dc355
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index f18cd81..37b9665 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -1079,6 +1079,26 @@
return __sflush(fp);
}
+int fpurge(FILE* fp) {
+ CHECK_FP(fp);
+
+ ScopedFileLock sfl(fp);
+
+ if (fp->_flags == 0) {
+ // Already freed!
+ errno = EBADF;
+ return EOF;
+ }
+
+ if (HASUB(fp)) FREEUB(fp);
+ WCIO_FREE(fp);
+ fp->_p = fp->_bf._base;
+ fp->_r = 0;
+ fp->_w = fp->_flags & (__SLBF | __SNBF) ? 0 : fp->_bf._size;
+ return 0;
+}
+__strong_alias(__fpurge, fpurge);
+
size_t fread(void* buf, size_t size, size_t count, FILE* fp) {
CHECK_FP(fp);
ScopedFileLock sfl(fp);