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 --- tests/stdio_test.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/stdio_test.cpp') diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 636b50481..8747dfc6d 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -1307,3 +1307,25 @@ TEST(STDIO_TEST, ctermid) { 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); +} -- cgit v1.2.3