diff --git a/src/database.c b/src/database.c index 26b8519..7a8ff79 100644 --- a/src/database.c +++ b/src/database.c @@ -142,7 +142,13 @@ int imdb_read_rec(imdb_t *db, imdb_rec_t *rec) DB_SEEK(db, rec->num * IMDB_REC_LEN); DB_READ(db, rec->data, IMDB_REC_LEN); - return bytes / IMDB_REC_LEN; + if (bytes != IMDB_REC_LEN) + return -1; + + if (rec->data[0] != 0xFF) + return 0; + + return 1; } int imdb_write_rec(imdb_t *db, imdb_rec_t *rec) diff --git a/src/database.h b/src/database.h index 719125a..cdff73e 100644 --- a/src/database.h +++ b/src/database.h @@ -74,6 +74,10 @@ typedef struct { float diff; } imdb_match_t; +/** + * @return 1 on success, 0 if record not used + * and -1 if record number not exists, + */ extern int imdb_read_rec (imdb_t *db, imdb_rec_t *rec); extern int imdb_write_rec(imdb_t *db, imdb_rec_t *rec);