]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test_short_dio_read.c: add error handling
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Tue, 12 Feb 2013 16:01:49 +0000 (17:01 +0100)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Fri, 15 Feb 2013 09:21:57 +0000 (10:21 +0100)
Add error handling for open() calls.

Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
qa/workunits/direct_io/test_short_dio_read.c

index 7cc43959747cf1bd236a9c5ec22195f5516844b9..f65ce4546bd01aa78fc5cf01d42e4719f57e1272 100644 (file)
@@ -3,12 +3,22 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
 
 int main()
 {
         char buf[409600];
-        int fd = open("shortfile", O_WRONLY|O_CREAT, 0644);
         ssize_t r;
+       int err;
+       int fd = open("shortfile", O_WRONLY|O_CREAT, 0644);
+
+       if (fd < 0) {
+               err = errno;
+               printf("error: open() failed with: %d (%s)\n", err, strerror(err));
+               exit(err);
+       }
 
        printf("writing first 3 bytes of 10k file\n");
         r = write(fd, "foo", 3);
@@ -18,6 +28,12 @@ int main()
 
        printf("reading O_DIRECT\n");
         fd = open("shortfile", O_RDONLY|O_DIRECT);
+       if (fd < 0) {
+               err = errno;
+               printf("error: open() failed with: %d (%s)\n", err, strerror(err));
+               exit(err);
+       }
+
         r = read(fd, buf, sizeof(buf));
         close(fd);