From: Uwe Hermann Date: Mon, 28 May 2012 22:21:21 +0000 (+0200) Subject: sr: la8 in: Files must be exactly 8388613 bytes. X-Git-Tag: libsigrok-0.1.1~15 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3217b032053d6eb89ca31b01968715813bcbe1bb;p=libsigrok.git sr: la8 in: Files must be exactly 8388613 bytes. All ChronoVu LA8 files (*.kdt extension usually) are exactly 8388613 bytes in size (8MB + 5 bytes). Check this, when trying to autodetect the file format, to reduce the likelihood of 'chronovu-la8' being autodetected on all binary files (instead of 'binary'). --- diff --git a/input/chronovu_la8.c b/input/chronovu_la8.c index 23a8dc09..f0a1a071 100644 --- a/input/chronovu_la8.c +++ b/input/chronovu_la8.c @@ -49,6 +49,9 @@ static uint64_t divcount_to_samplerate(uint8_t divcount) static int format_match(const char *filename) { + struct stat stat_buf; + int ret; + if (!filename) { sr_err("la8 in: %s: filename was NULL", __func__); // return SR_ERR; /* FIXME */ @@ -69,7 +72,19 @@ static int format_match(const char *filename) return FALSE; } - /* TODO: Only accept files of length 8MB + 5 bytes. */ + /* Only accept files of length 8MB + 5 bytes. */ + ret = stat(filename, &stat_buf); + if (ret != 0) { + sr_err("la8 in: %s: Error getting file size of '%s'", + __func__, filename); + return FALSE; + } + if (stat_buf.st_size != (8 * 1024 * 1024 + 5)) { + sr_dbg("la8 in: %s: File size must be exactly 8388613 bytes (" + "it actually is %d bytes in size), so this is not a " + "ChronoVu LA8 file.", __func__, stat_buf.st_size); + return FALSE; + } /* TODO: Check for divcount != 0xff. */