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
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 53b3fae..23a54de 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -741,6 +741,12 @@
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);