sr: better file version check

Still not really used though.
This commit is contained in:
Bert Vermeulen 2012-07-23 15:08:44 +02:00
parent 056be0719f
commit c1864d5589
1 changed files with 10 additions and 4 deletions

View File

@ -48,9 +48,9 @@ SR_API int sr_session_load(const char *filename)
struct zip_stat zs; struct zip_stat zs;
struct sr_dev_inst *sdi; struct sr_dev_inst *sdi;
struct sr_probe *probe; struct sr_probe *probe;
int ret, probenum, devcnt, i, j; int ret, probenum, devcnt, version, i, j;
uint64_t tmp_u64, total_probes, enabled_probes, p; uint64_t tmp_u64, total_probes, enabled_probes, p;
char **sections, **keys, *metafile, *val, c; char **sections, **keys, *metafile, *val, s[11];
char probename[SR_MAX_PROBENAME_LEN + 1]; char probename[SR_MAX_PROBENAME_LEN + 1];
if (!filename) { if (!filename) {
@ -65,16 +65,22 @@ SR_API int sr_session_load(const char *filename)
} }
/* check "version" */ /* check "version" */
version = 0;
if (!(zf = zip_fopen(archive, "version", 0))) { if (!(zf = zip_fopen(archive, "version", 0))) {
sr_dbg("session file: Not a sigrok session file."); sr_dbg("session file: Not a sigrok session file.");
return SR_ERR; return SR_ERR;
} }
ret = zip_fread(zf, &c, 1); if ((ret = zip_fread(zf, s, 10)) == -1) {
if (ret != 1 || c != '1') {
sr_dbg("session file: Not a valid sigrok session file."); sr_dbg("session file: Not a valid sigrok session file.");
return SR_ERR; return SR_ERR;
} }
zip_fclose(zf); zip_fclose(zf);
s[ret] = 0;
version = strtoull(s, NULL, 10);
if (version != 1) {
sr_dbg("session file: Not a valid sigrok session file version.");
return SR_ERR;
}
/* read "metadata" */ /* read "metadata" */
if (zip_stat(archive, "metadata", 0, &zs) == -1) { if (zip_stat(archive, "metadata", 0, &zs) == -1) {