]> cvs.zerfleddert.de Git - rigol/blobdiff - rigol.c
don't continue when malloc bails out
[rigol] / rigol.c
diff --git a/rigol.c b/rigol.c
index 818b7eac797ce22dad13eb170611604a7d13dd71..0e9ff9e9e5bbe226322a220eba4f904344dccff7 100644 (file)
--- a/rigol.c
+++ b/rigol.c
@@ -306,6 +306,7 @@ void do_get_screen(struct usb_dev_handle *sc)
        char filename[256];
        unsigned char *png;
        int imglen;
        char filename[256];
        unsigned char *png;
        int imglen;
+       int ret;
        int l;
        int fd;
        pid_t display;
        int l;
        int fd;
        pid_t display;
@@ -320,11 +321,26 @@ void do_get_screen(struct usb_dev_handle *sc)
                printf ("hmm. didnt' get %d bytes, but %d\n\n", sizeof(screen), l); 
        }
 
                printf ("hmm. didnt' get %d bytes, but %d\n\n", sizeof(screen), l); 
        }
 
+       png = lcd2png(screen, &imglen);
+
+       lt = time(NULL);
        strftime(filename, sizeof(filename), "screen_%Y%m%d-%H%M%S.png", localtime(&lt));
        fd=open(filename, O_CREAT|O_WRONLY, 0644);
        strftime(filename, sizeof(filename), "screen_%Y%m%d-%H%M%S.png", localtime(&lt));
        fd=open(filename, O_CREAT|O_WRONLY, 0644);
-       png = lcd2png(screen, &imglen);
-       write(fd, png, imglen);
+       if (fd == -1) {
+               perror("open");
+               exit(EXIT_FAILURE);
+       }
+
+       while(imglen > 0) {
+               ret = write(fd, png, imglen);
+               if (ret == -1) {
+                       perror("write");
+                       exit(EXIT_FAILURE);
+               }
+               imglen -= ret;
+       }
        close(fd);
        close(fd);
+       free(png);
 
        printf("Waveform saved as %s\n", filename);
 
 
        printf("Waveform saved as %s\n", filename);
 
Impressum, Datenschutz