diff options
author | Andreas Kling <awesomekling@gmail.com> | 2020-01-03 03:36:17 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2020-01-03 03:36:17 +0100 |
commit | 93e9a42bf04a1ec841353e7b1959107c731d60ad (patch) | |
tree | 4013d1c659e00065b8481b3a7b40ac92bf5049b1 /Userland | |
parent | c19f840f32ef07592091e040446e8021e2cca4a9 (diff) | |
download | serenity-93e9a42bf04a1ec841353e7b1959107c731d60ad.zip |
test_io: Verify that write() on an O_RDONLY fd fails with EBADF
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/test_io.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Userland/test_io.cpp b/Userland/test_io.cpp index 043fc2360d..2296dff418 100644 --- a/Userland/test_io.cpp +++ b/Userland/test_io.cpp @@ -64,6 +64,17 @@ void test_read_from_writeonly() ASSERT(rc == 0); } +void test_write_to_readonly() +{ + char str[] = "hello"; + int fd = open("/tmp/abcd123", O_CREAT | O_RDONLY); + ASSERT(fd >= 0); + int rc; + EXPECT_ERROR_3(EBADF, write, fd, str, sizeof(str)); + rc = close(fd); + ASSERT(rc == 0); +} + int main(int, char**) { int rc; @@ -78,6 +89,7 @@ int main(int, char**) test_read_from_directory(); test_write_to_directory(); test_read_from_writeonly(); + test_write_to_readonly(); return 0; } |