Browse Source

* drop simdb_record_write(), simdb_rec_t, simdb_block_t, DB_{READ,WRITE} macro

master
Alex 'AdUser' Z 8 years ago
parent
commit
fadb954e89
  1. 31
      src/database.c
  2. 27
      src/simdb.h

31
src/database.c

@ -31,19 +31,6 @@ struct _simdb_t {
char path[PATH_MAX]; /**< path to database file */
};
/** read some records from database file and checks for errors */
#define DB_READ(db, buf, len, off) \
errno = 0; \
memset((buf), 0x0, (len)); \
bytes = pread((db)->fd, (buf), (len), (off)); \
if (errno) { return SIMDB_ERR_SYSTEM; }
/** write some records from database file and checks for errors */
#define DB_WRITE(db, buf, len, off) \
errno = 0; \
bytes = pwrite((db)->fd, (buf), (len), (off)); \
if (errno) { return SIMDB_ERR_SYSTEM; }
/** database header format line */
const char *simdb_hdr_fmt = "IMDB v%02u, CAPS: %s;";
@ -237,24 +224,6 @@ simdb_write(simdb_t *db, int start, int records, simdb_urec_t *data) {
return records;
}
int simdb_record_write(simdb_t *db, simdb_rec_t *rec) {
ssize_t bytes = 0;
assert(db != NULL);
assert(rec != NULL);
assert(rec->num > 0);
if (!(db->flags & SIMDB_FLAG_WRITE))
return SIMDB_ERR_READONLY;
DB_WRITE(db, rec->data, SIMDB_REC_LEN, rec->num * SIMDB_REC_LEN);
if (bytes != SIMDB_REC_LEN)
return SIMDB_ERR_SYSTEM;
return 1;
}
int
simdb_records_count(simdb_t * const db) {
struct stat st;

27
src/simdb.h

@ -40,23 +40,6 @@
/** opaque database handler */
typedef struct _simdb_t simdb_t;
/**
* database record
*/
typedef struct {
uint64_t num; /**< record number in database */
unsigned char data[SIMDB_REC_LEN]; /**< record raw data */
} simdb_rec_t;
/**
* block of sequental records of database
*/
typedef struct {
uint64_t start; /**< first record number of block */
size_t records; /**< records count */
unsigned char *data; /**< raw records data */
} simdb_block_t;
/**
* search parameters
* maxdiff_* fields should have value from 0.0 to 1.0 (0% - 100%)
@ -121,16 +104,6 @@ int simdb_search(simdb_t * const db, int num,
simdb_search_t * const search,
simdb_match_t ** matches);
/**
* @brief Write single record to database
* @param db Database handle
* @param rec Record struct to write
* @note @a num member of @a rec struct should be set
* @retval 1 on success
* @retval <0 on error (system error or record missing)
*/
int simdb_record_write(simdb_t *db, simdb_rec_t *rec);
/**
* @brief Create record from image file
* @param path Path to source image

Loading…
Cancel
Save