From d1f25a7eb171b490be59271e9ce619e236421aeb Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 5 Aug 2016 15:53:03 -0700 Subject: 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 --- libc/stdio/stdio.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libc/stdio/stdio.cpp') 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); -- cgit v1.2.3