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/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 636b504..8747dfc 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -1307,3 +1307,25 @@
   ASSERT_EQ(buf, ctermid(buf));
   ASSERT_STREQ("/dev/tty", buf);
 }
+
+TEST(STDIO_TEST, remove) {
+  struct stat sb;
+
+  TemporaryFile tf;
+  ASSERT_EQ(0, remove(tf.filename));
+  ASSERT_EQ(-1, lstat(tf.filename, &sb));
+  ASSERT_EQ(ENOENT, errno);
+
+  TemporaryDir td;
+  ASSERT_EQ(0, remove(td.dirname));
+  ASSERT_EQ(-1, lstat(td.dirname, &sb));
+  ASSERT_EQ(ENOENT, errno);
+
+  errno = 0;
+  ASSERT_EQ(-1, remove(tf.filename));
+  ASSERT_EQ(ENOENT, errno);
+
+  errno = 0;
+  ASSERT_EQ(-1, remove(td.dirname));
+  ASSERT_EQ(ENOENT, errno);
+}