aboutsummaryrefslogtreecommitdiffstats
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-09-23 17:34:29 -0700
committerElliott Hughes <enh@google.com>2014-09-23 18:21:52 -0700
commit31165edf5733dae8fbe79551b18cbc0e56c8d808 (patch)
treee7ed184d94540342f16514a84e02c1f8d38882db /tests/stdio_test.cpp
parent87b6906f6e0c17b2541535be8e054324cc2fef4a (diff)
downloadandroid_bionic-31165edf5733dae8fbe79551b18cbc0e56c8d808.tar.gz
android_bionic-31165edf5733dae8fbe79551b18cbc0e56c8d808.tar.bz2
android_bionic-31165edf5733dae8fbe79551b18cbc0e56c8d808.zip
CLOEXEC support in fdopen, freopen, and mkostemp/mkostemps.
Change-Id: I74ea88e0d4973d6ab3c57da7d8bb643c31592b14
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index c01ab683c..6a653b4dd 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -756,3 +756,43 @@ TEST(stdio, open_memstream_EINVAL) {
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
+
+TEST(stdio, fdopen_CLOEXEC) {
+ int fd = open("/proc/version", O_RDONLY);
+ ASSERT_TRUE(fd != -1);
+
+ // This fd doesn't have O_CLOEXEC...
+ int flags = fcntl(fd, F_GETFD);
+ ASSERT_TRUE(flags != -1);
+ ASSERT_EQ(0, flags & FD_CLOEXEC);
+
+ FILE* fp = fdopen(fd, "re");
+ ASSERT_TRUE(fp != NULL);
+
+ // ...but the new one does.
+ flags = fcntl(fileno(fp), F_GETFD);
+ ASSERT_TRUE(flags != -1);
+ ASSERT_EQ(FD_CLOEXEC, flags & FD_CLOEXEC);
+
+ fclose(fp);
+ close(fd);
+}
+
+TEST(stdio, freopen_CLOEXEC) {
+ FILE* fp = fopen("/proc/version", "r");
+ ASSERT_TRUE(fp != NULL);
+
+ // This FILE* doesn't have O_CLOEXEC...
+ int flags = fcntl(fileno(fp), F_GETFD);
+ ASSERT_TRUE(flags != -1);
+ ASSERT_EQ(0, flags & FD_CLOEXEC);
+
+ fp = freopen("/proc/version", "re", fp);
+
+ // ...but the new one does.
+ flags = fcntl(fileno(fp), F_GETFD);
+ ASSERT_TRUE(flags != -1);
+ ASSERT_EQ(FD_CLOEXEC, flags & FD_CLOEXEC);
+
+ fclose(fp);
+}