nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 239aec3926ca588d7e0c04ed3005741f4224b630
parent 83359274abde2c9422df10af2f7565396a08a757
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 11 Apr 2020 11:20:29 -0400

nserver/src/db.c: Add mk_datum.

* nserver/src/db.c (mk_datum): New function.

Diffstat:
nserver/src/db.c | 23++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/nserver/src/db.c b/nserver/src/db.c @@ -1,13 +1,34 @@ #include <db.h> - static const char *DB_FILE = "nserver.db"; +datum *mk_datum(char *data) +{ + datum *d = NULL; + + check(data != NULL, "data invalid"); + + d = calloc(1, sizeof(datum)); + check(d != NULL, "datum mem alloc failed"); + + d->dptr = data; + d->dsize = strlen(data) + 2; + + return d; + error: + if (d) { + free(d); + } + return NULL; +} + + GDBM_FILE db_open(int flags) { return gdbm_open(DB_FILE, 0,flags, S_IRUSR|S_IWUSR, NULL); } + int db_init() { // Create DB if it's not already created.