summaryrefslogtreecommitdiff
path: root/libc/stdio/stdio.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-10-01 14:21:07 -0700
committerElliott Hughes <enh@google.com>2018-10-01 16:17:37 -0700
commit22917f63ee9ff25f629167b4a54f7d8be37da505 (patch)
treea44ac1fae0dc4cc1f405096ef6cfd6e981afd5db /libc/stdio/stdio.cpp
parent7208139406adbd40782ccd7554e1a21458da2b37 (diff)
Make fclose/pclose distinct.
I failed to convince the compiler/linker to just refrain (via factoring out, attribute `noinline`, or meddling with `--icf=none`), but luckily I noticed that we should have CHECK_FP in each function for a better error message, and the distinct error messages keep the two functions apart. (Also add a missing CHECK_FP to `clearerr_unlocked`.) Bug: http://b/116969207 Test: manual with a modified `crasher` Change-Id: Ic122e90e94f7e22f486be57d3dac7137a225d682
Diffstat (limited to 'libc/stdio/stdio.cpp')
-rw-r--r--libc/stdio/stdio.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 71fdd273e..d7b69dcb5 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -404,8 +404,7 @@ FILE* freopen(const char* file, const char* mode, FILE* fp) {
}
__strong_alias(freopen64, freopen);
-int fclose(FILE* fp) {
- CHECK_FP(fp);
+static int __FILE_close(FILE* fp) {
if (fp->_flags == 0) {
// Already freed!
errno = EBADF;
@@ -440,7 +439,11 @@ int fclose(FILE* fp) {
fp->_flags = 0;
return r;
}
-__strong_alias(pclose, fclose);
+
+int fclose(FILE* fp) {
+ CHECK_FP(fp);
+ return __FILE_close(fp);
+}
int fileno_unlocked(FILE* fp) {
CHECK_FP(fp);
@@ -459,6 +462,7 @@ int fileno(FILE* fp) {
}
void clearerr_unlocked(FILE* fp) {
+ CHECK_FP(fp);
return __sclearerr(fp);
}
@@ -1235,6 +1239,11 @@ FILE* popen(const char* cmd, const char* mode) {
return fp;
}
+int pclose(FILE* fp) {
+ CHECK_FP(fp);
+ return __FILE_close(fp);
+}
+
namespace {
namespace phony {