From 8c1c8cc2ef43e84ff5bcd862a0cdf61b1cc02edb Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 19 Mar 2015 18:09:08 +1000 Subject: [PATCH] * read db capabilities on start --- src/database.c | 12 ++++++++++-- src/database.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/database.c b/src/database.c index 57d8543..d13cc2d 100644 --- a/src/database.c +++ b/src/database.c @@ -70,13 +70,21 @@ int imdb_open(imdb_t *db, const char *path) db->path = path; + memset(buf, 0x0, IMDB_REC_LEN); if (init) { - memset(buf, 0x0, IMDB_REC_LEN); snprintf((char *) buf, IMDB_REC_LEN, imdb_hdr_fmt, IMDB_VERSION, "M-R"); DB_SEEK(db, 0); DB_WRITE(db, buf, IMDB_REC_LEN); - return bytes / IMDB_REC_LEN; + if (bytes != IMDB_REC_LEN) + return -1; + memcpy(db->caps, "M-R", sizeof(char) * 3); + } else { + DB_SEEK(db, 0); + DB_READ(db, buf, IMDB_REC_LEN); + if (bytes != IMDB_REC_LEN) + return -1; + memcpy(db->caps, buf + 16, sizeof(char) * 8); } return 0; diff --git a/src/database.h b/src/database.h index 07d7165..2bccd49 100644 --- a/src/database.h +++ b/src/database.h @@ -9,6 +9,7 @@ typedef struct { int fd; const char *path; const char *errstr; + unsigned char caps[8]; } imdb_t; typedef struct {