aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-02-24 05:55:37 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-02-24 05:55:37 +0000
commit2aef607b25c463baed5ae70d14212e24ea7bcf2b (patch)
tree0f58f6022d63e08166da1a03775d50df4d2f13b5 /tests
parent393bdb156d5024a03f03425a977d0518c84dbb98 (diff)
parentbe52e658171edf6651895c40d1563289bafa52f7 (diff)
downloadandroid_bionic-2aef607b25c463baed5ae70d14212e24ea7bcf2b.tar.gz
android_bionic-2aef607b25c463baed5ae70d14212e24ea7bcf2b.tar.bz2
android_bionic-2aef607b25c463baed5ae70d14212e24ea7bcf2b.zip
Merge "Fix dup2 in the case where the two fds are equal."
Diffstat (limited to 'tests')
-rw-r--r--tests/unistd_test.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index f5c0524c4..f54a4619b 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -801,3 +801,22 @@ TEST(unistd, sysconf) {
VERIFY_SYSCONF_NOT_SUPPORT(_SC_XOPEN_UUCP);
#endif // defined(__BIONIC__)
}
+
+TEST(unistd, dup2_same) {
+ // POSIX says of dup2:
+ // If fildes2 is already a valid open file descriptor ...
+ // [and] fildes is equal to fildes2 ... dup2() shall return
+ // fildes2 without closing it.
+ // This isn't true of dup3(2), so we need to manually implement that.
+
+ // Equal and valid.
+ int fd = open("/proc/version", O_RDONLY);
+ ASSERT_TRUE(fd != -1);
+ ASSERT_EQ(fd, dup2(fd, fd));
+ ASSERT_EQ(0, close(fd)); // Check that dup2 didn't close fd.
+
+ // Equal, but invalid.
+ errno = 0;
+ ASSERT_EQ(-1, dup2(fd, fd));
+ ASSERT_EQ(EBADF, errno);
+}