]> sigrok.org Git - libsigrok.git/blobdiff - session_file.c
Detect non-existent file before libzip does.
[libsigrok.git] / session_file.c
index 0e7ad2d8b9befb5995e2b2cedea42019c4f4fe51..d720dd599eae866299b987fc5a1c2873b2ceb72f 100644 (file)
@@ -21,6 +21,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <zip.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
 #include <glib.h>
 #include <glib/gstdio.h>
 #include "config.h" /* Needed for PACKAGE_VERSION and others. */
@@ -54,6 +57,7 @@ extern SR_PRIV struct sr_dev_driver session_driver;
 /** @private */
 SR_PRIV int sr_sessionfile_check(const char *filename)
 {
+       struct stat st;
        struct zip *archive;
        struct zip_file *zf;
        struct zip_stat zs;
@@ -63,6 +67,11 @@ SR_PRIV int sr_sessionfile_check(const char *filename)
        if (!filename)
                return SR_ERR_ARG;
 
+       if (stat(filename, &st) == -1) {
+               sr_err("Couldn't stat %s: %s", filename, strerror(errno));
+               return SR_ERR;
+       }
+
        if (!(archive = zip_open(filename, 0, &ret)))
                /* No logging: this can be used just to check if it's
                 * a sigrok session file or not. */