From 4a37f289c05851c4b5f9906fa2e6fd5cf23153c1 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 9 Jan 2017 17:20:27 +1000 Subject: [PATCH] * drop simdb_{record,block}_read() --- src/database.c | 34 ------------------------ src/simdb.h | 20 -------------- tests/CMakeLists.txt | 3 --- tests/database.c | 62 -------------------------------------------- 4 files changed, 119 deletions(-) delete mode 100644 tests/database.c diff --git a/src/database.c b/src/database.c index 2df4327..1db26f2 100644 --- a/src/database.c +++ b/src/database.c @@ -237,24 +237,6 @@ simdb_write(simdb_t *db, int start, int records, simdb_urec_t *data) { return records; } -int simdb_record_read(simdb_t *db, simdb_rec_t *rec) { - ssize_t bytes = 0; - - assert(db != NULL); - assert(rec != NULL); - assert(rec->num > 0); - - DB_READ(db, rec->data, SIMDB_REC_LEN, rec->num * SIMDB_REC_LEN); - - if (bytes != SIMDB_REC_LEN) - return errno ? SIMDB_ERR_SYSTEM : SIMDB_ERR_NXRECORD; - - if (rec->data[0] != 0xFF) - return 0; - - return 1; -} - int simdb_record_write(simdb_t *db, simdb_rec_t *rec) { ssize_t bytes = 0; @@ -273,22 +255,6 @@ int simdb_record_write(simdb_t *db, simdb_rec_t *rec) { return 1; } -int simdb_block_read(simdb_t *db, simdb_block_t *blk) { - ssize_t bytes = 0; - - assert(db != NULL); - assert(blk != NULL); - assert(blk->start > 0); - assert(blk->records > 0); - - FREE(blk->data); - CALLOC(blk->data, blk->records, SIMDB_REC_LEN); - DB_READ(db, blk->data, blk->records * SIMDB_REC_LEN, blk->start * SIMDB_REC_LEN); - blk->records = bytes / SIMDB_REC_LEN; - - return blk->records; -} - int simdb_records_count(simdb_t * const db) { struct stat st; diff --git a/src/simdb.h b/src/simdb.h index ba82243..f55f2ae 100644 --- a/src/simdb.h +++ b/src/simdb.h @@ -121,16 +121,6 @@ int simdb_search(simdb_t * const db, int num, simdb_search_t * const search, simdb_match_t ** matches); -/** - * @brief Read single record from database - * @param db Database handle - * @param rec Record struct - * @note @a num member of @a rec struct should be set - * @retval 1 on success - * @retval 0 if record exists but not used, - * @retval <0 on error (system error or record missing) - */ -int simdb_record_read(simdb_t *db, simdb_rec_t *rec); /** * @brief Write single record to database * @param db Database handle @@ -148,16 +138,6 @@ int simdb_record_write(simdb_t *db, simdb_rec_t *rec); */ bool simdb_record_create(simdb_rec_t * const rec, const char *path); -/** - * @brief Read continious records block from database - * @param db Database handle - * @param blk Block struct - * @note @a start and @a records members of @a blk struct should be set - * @retval >=0 As number of records actually read - * @retval <0 on error - */ -int simdb_block_read(simdb_t *db, simdb_block_t *blk); - /** * @brief Get database capacity */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e75563c..3aef81d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,6 +6,3 @@ add_test("test/record" "test-record") add_executable("test-io" "io.c" "../src/database.c" "../src/bitmap.c") add_test("test/io" "test-io") - -add_executable("test-database" "database.c" "../src/database.c" "../src/bitmap.c") -add_test("test/database" "test-database") diff --git a/tests/database.c b/tests/database.c deleted file mode 100644 index a0ba5aa..0000000 --- a/tests/database.c +++ /dev/null @@ -1,62 +0,0 @@ -#include "../src/common.h" -#include "../src/simdb.h" - -int main() { - simdb_t *db; - simdb_rec_t rec[2]; - simdb_block_t blk; - char *path = "test.db"; - int mode = 0, err = 0, num; - bool ret; - - unlink(path); - - db = simdb_open(path, mode, &err); - assert(db == NULL); - assert(err == -1); /* no such file */ - - ret = simdb_create(path); - assert(ret == true); - - db = simdb_open(path, mode, &err); - assert(db != NULL); - - rec[0].num = 1; - err = simdb_record_read(db, rec); - assert(err == SIMDB_ERR_NXRECORD); - - memset(rec[0].data, 0xAA, SIMDB_REC_LEN); - memset(rec[0].data, 0xFF, 1); /* record is used */ - - num = simdb_record_write(db, rec); - assert(num == SIMDB_ERR_READONLY); /* database open in read-only mode */ - - simdb_close(db); - - mode |= SIMDB_FLAG_WRITE; - db = simdb_open(path, mode, &err); - assert(db != NULL); - - num = simdb_record_write(db, rec); - assert(num == 1); /* success */ - - num = simdb_record_read(db, rec); - assert(num == 1); - - blk.start = 1; - blk.records = 2; - blk.data = NULL; - num = simdb_block_read(db, &blk); - assert(num == 1); - assert(blk.records == 1); - assert(blk.data != NULL); - - rec[0].num = 1; - rec[1].num = 3; - - simdb_close(db); - - unlink(path); - - return 0; -}