summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-03 03:33:34 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-03 03:34:06 +0100
commitc19f840f32ef07592091e040446e8021e2cca4a9 (patch)
tree1176ba9f96f5147f0fc52fb08be78d09c8ee36b0
parent0a1865ebc6a0df78464c63064e1e3e61384441bc (diff)
downloadserenity-c19f840f32ef07592091e040446e8021e2cca4a9.zip
test_io: Verify that read() on an O_WRONLY fd fails with EBADF
-rw-r--r--Userland/test_io.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/Userland/test_io.cpp b/Userland/test_io.cpp
index 2ee3fdf936..043fc2360d 100644
--- a/Userland/test_io.cpp
+++ b/Userland/test_io.cpp
@@ -53,6 +53,17 @@ void test_write_to_directory()
ASSERT(rc == 0);
}
+void test_read_from_writeonly()
+{
+ char buffer[BUFSIZ];
+ int fd = open("/tmp/xxxx123", O_CREAT | O_WRONLY);
+ ASSERT(fd >= 0);
+ int rc;
+ EXPECT_ERROR_3(EBADF, read, fd, buffer, sizeof(buffer));
+ rc = close(fd);
+ ASSERT(rc == 0);
+}
+
int main(int, char**)
{
int rc;
@@ -66,6 +77,7 @@ int main(int, char**)
test_read_from_directory();
test_write_to_directory();
+ test_read_from_writeonly();
return 0;
}