summaryrefslogtreecommitdiff
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-05-02 18:29:25 -0700
committerElliott Hughes <enh@google.com>2014-05-05 14:31:20 -0700
commit53b24382f5299931af5d08c933a765334a092c56 (patch)
tree6ffbf015c42e0f140740f3c6cbdb41e8b28e9b80 /tests/stdio_test.cpp
parente987803c35b472f378f81a37beb162ac86e01503 (diff)
Switch to current upstream OpenBSD wsetup.c.
Change-Id: I2c1123f3e1d3c4af7fd7bf354e763934a39b78c0
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index d825c14ec..ebb27d4a5 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -436,3 +436,45 @@ TEST(stdio, sscanf) {
ASSERT_EQ(123, i1);
ASSERT_DOUBLE_EQ(1.23, d1);
}
+
+TEST(stdio, cantwrite_EBADF) {
+ // If we open a file read-only...
+ FILE* fp = fopen("/proc/version", "r");
+
+ // ...all attempts to write to that file should return failure.
+
+ // They should also set errno to EBADF. This isn't POSIX, but it's traditional.
+ // glibc gets the wide-character functions wrong.
+
+ errno = 0;
+ EXPECT_EQ(EOF, putc('x', fp));
+ EXPECT_EQ(EBADF, errno);
+
+ errno = 0;
+ EXPECT_EQ(EOF, fprintf(fp, "hello"));
+ EXPECT_EQ(EBADF, errno);
+
+ errno = 0;
+ EXPECT_EQ(EOF, fwprintf(fp, L"hello"));
+#if !defined(__GLIBC__)
+ EXPECT_EQ(EBADF, errno);
+#endif
+
+ errno = 0;
+ EXPECT_EQ(EOF, putw(1234, fp));
+ EXPECT_EQ(EBADF, errno);
+
+ errno = 0;
+ EXPECT_EQ(0U, fwrite("hello", 1, 2, fp));
+ EXPECT_EQ(EBADF, errno);
+
+ errno = 0;
+ EXPECT_EQ(EOF, fputs("hello", fp));
+ EXPECT_EQ(EBADF, errno);
+
+ errno = 0;
+ EXPECT_EQ(WEOF, fputwc(L'x', fp));
+#if !defined(__GLIBC__)
+ EXPECT_EQ(EBADF, errno);
+#endif
+}