diff --git a/src/database.c b/src/database.c index 804640b..2ff2356 100644 --- a/src/database.c +++ b/src/database.c @@ -231,6 +231,25 @@ simdb_write(simdb_t *db, int start, int records, simdb_urec_t *data) { return records; } +bool +simdb_record_used(simdb_t *db, int num) { + simdb_urec_t *rec = NULL; + bool ret = false; + + assert(db != NULL); + + if (num > db->records) + return false; + + if (simdb_read(db, num, 1, &rec) < 1) + return false; + + ret = rec->used ? true : false; + + FREE(rec); + return ret; +} + int simdb_record_del(simdb_t *db, int num) { simdb_urec_t *rec; diff --git a/src/simdb.h b/src/simdb.h index 4782f7d..8fa74f2 100644 --- a/src/simdb.h +++ b/src/simdb.h @@ -105,6 +105,14 @@ int simdb_search(simdb_t * const db, int num, simdb_search_t * const search, simdb_match_t ** matches); +/** + * @brief Checks is record with given number is used + * @param db Database handle + * @param num Record number + * @returns true if used, false if no record exists or not used + */ +bool simdb_record_used(simdb_t *db, int num); + /** * @brief Create record from image file * @param path Path to source image