Browse Source

+ imdb_init()

master
Alex 'AdUser' Z 10 years ago
parent
commit
d79d7f6532
  1. 24
      src/database.c
  2. 1
      src/database.h

24
src/database.c

@ -47,6 +47,30 @@
const char *imdb_hdr_fmt = "IMDB v%02u, CAPS: %s;";
int imdb_init(imdb_t *db, const char *path)
{
ssize_t bytes = 0;
unsigned char buf[IMDB_REC_LEN];
memset(buf, 0x0, sizeof(char) * IMDB_REC_LEN);
if ((db->fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) {
db->errstr = strerror(errno);
return -1;
}
snprintf((char *) buf, IMDB_REC_LEN, imdb_hdr_fmt, IMDB_VERSION, "M-R");
DB_SEEK(db, 0);
DB_WRITE(db, buf, IMDB_REC_LEN);
if (bytes != IMDB_REC_LEN) {
db->errstr = "Can't write database header";
return -1;
}
return 0;
}
int imdb_open(imdb_t *db, const char *path)
{
int init = 0;

1
src/database.h

@ -83,6 +83,7 @@ extern int imdb_write_blk(imdb_t *db, imdb_block_t *blk);
extern int imdb_read_list (imdb_t *db, imdb_rec_t *list, size_t list_len);
extern int imdb_write_list(imdb_t *db, imdb_rec_t *list, size_t list_len);
extern int imdb_init (imdb_t *db, const char *path);
extern int imdb_open (imdb_t *db, const char *path);
extern int imdb_close(imdb_t *db);

Loading…
Cancel
Save