Преглед изворни кода

test_io: Verify that write() on an O_RDONLY fd fails with EBADF

Andreas Kling пре 5 година
родитељ
комит
93e9a42bf0
1 измењених фајлова са 12 додато и 0 уклоњено
  1. 12 0
      Userland/test_io.cpp

+ 12 - 0
Userland/test_io.cpp

@@ -64,6 +64,17 @@ void test_read_from_writeonly()
     ASSERT(rc == 0);
     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 main(int, char**)
 {
 {
     int rc;
     int rc;
@@ -78,6 +89,7 @@ int main(int, char**)
     test_read_from_directory();
     test_read_from_directory();
     test_write_to_directory();
     test_write_to_directory();
     test_read_from_writeonly();
     test_read_from_writeonly();
+    test_write_to_readonly();
 
 
     return 0;
     return 0;
 }
 }