aboutsummaryrefslogtreecommitdiffstats
path: root/tests/stdio_test.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 /tests/stdio_test.cpp
parented9e6a41c92c9552be84ecc126e29b4604eee246 (diff)
downloadandroid_bionic-d1f25a7eb171b490be59271e9ce619e236421aeb.tar.gz
android_bionic-d1f25a7eb171b490be59271e9ce619e236421aeb.tar.bz2
android_bionic-d1f25a7eb171b490be59271e9ce619e236421aeb.zip
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 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp22
1 files changed, 22 insertions, 0 deletions
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);
+}