Browse Source

* read db capabilities on start

master
Alex 'AdUser' Z 9 years ago
parent
commit
8c1c8cc2ef
  1. 12
      src/database.c
  2. 1
      src/database.h

12
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;

1
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 {

Loading…
Cancel
Save