From: Bert Vermeulen Date: Wed, 11 Dec 2013 09:49:01 +0000 (+0100) Subject: Detect non-existent file before libzip does. X-Git-Tag: libsigrok-0.3.0~443 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;h=5f9c4c8a34e6c1d122d36efd2e8263f0456541bd;hp=1e7134dc8cff3f28a312e41c997ed488fb071e96;p=libsigrok.git Detect non-existent file before libzip does. --- diff --git a/session_file.c b/session_file.c index 0e7ad2d8..d720dd59 100644 --- a/session_file.c +++ b/session_file.c @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include #include #include #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. */