summaryrefslogtreecommitdiff
path: root/libc/stdio/stdio.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-08-05 15:53:03 -0700
committerElliott Hughes <enh@google.com>2016-08-05 15:53:03 -0700
commitd1f25a7eb171b490be59271e9ce619e236421aeb (patch)
treea094178ff6ae9af3f476c0480087a09a63a37000 /libc/stdio/stdio.cpp
parented9e6a41c92c9552be84ecc126e29b4604eee246 (diff)
Reimplement remove(3) without the lstat(2).
This assumes that it's more likely we're unlinking a file than a directory, though even if that's not true, as long as a failed unlink(2) is cheaper than a successful lstat(2) -- which seems likely since there's no data to copy -- we still win. Change-Id: I0210e9cd3d31b8cf1813c55c810262ef327382ed
Diffstat (limited to 'libc/stdio/stdio.cpp')
-rw-r--r--libc/stdio/stdio.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 53b3faeb1..23a54de35 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -741,6 +741,12 @@ wint_t putwchar(wchar_t wc) {
return fputwc(wc, stdout);
}
+int remove(const char* path) {
+ if (unlink(path) != -1) return 0;
+ if (errno != EISDIR) return -1;
+ return rmdir(path);
+}
+
void rewind(FILE* fp) {
ScopedFileLock sfl(fp);
fseek(fp, 0, SEEK_SET);