]> diplodocus.org Git - flac-archive/commitdiff
more error check
author <epg@pretzelnet.org> <>
Sun, 8 Dec 2013 23:21:29 +0000 (15:21 -0800)
committer <epg@pretzelnet.org> <>
Sun, 8 Dec 2013 23:21:29 +0000 (15:21 -0800)
apic-read.cc

index 194e3406eb219556d8107e962214dd0646d8b7ec..324450e411147437d656fac1a28c2534d570307e 100644 (file)
@@ -40,18 +40,23 @@ main(int argc, char **argv)
         AttachedPictureFrame *frame = (AttachedPictureFrame *)(*it);
         TagLib::ByteVector data = frame->picture();
         int fd = open(argv[2], O_CREAT | O_WRONLY);
         AttachedPictureFrame *frame = (AttachedPictureFrame *)(*it);
         TagLib::ByteVector data = frame->picture();
         int fd = open(argv[2], O_CREAT | O_WRONLY);
+        if (fd < 0) {
+            perror("open");
+            return 2;
+        }
         ssize_t size = data.size();
         ssize_t status = write(fd, data.data(), size);
         if (status < 0) {
             perror("write");
         ssize_t size = data.size();
         ssize_t status = write(fd, data.data(), size);
         if (status < 0) {
             perror("write");
-            return 2;
+            return 3;
         }
         if (status != size) {
             fprintf(stderr, "wrote only %d bytes out of %d\n", status, size);
         }
         if (status != size) {
             fprintf(stderr, "wrote only %d bytes out of %d\n", status, size);
-            return 3;
+            return 4;
         }
         if (close(fd) < 0) {
             perror("close");
         }
         if (close(fd) < 0) {
             perror("close");
+            return 5;
         }
     }
 
         }
     }