X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb.c;h=9468e604a7f9fbb0d420ef0c0c7ff8a0e5d51e97;hp=7dc5aafbfc254c7d865813e34172e0b29893423d;hb=18636637ee013ef828cb04b2b7bb4a4922324475;hpb=0455668028cfe8f0417037975bc3d7dd742974db diff --git a/ccan/tdb2/tdb.c b/ccan/tdb2/tdb.c index 7dc5aafb..9468e604 100644 --- a/ccan/tdb2/tdb.c +++ b/ccan/tdb2/tdb.c @@ -432,7 +432,7 @@ int tdb_store(struct tdb_context *tdb, struct tdb_used_record rec; int ret; - off = find_and_lock(tdb, key, F_WRLCK, &h, &rec); + off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL); if (unlikely(off == TDB_OFF_ERR)) return -1; @@ -494,7 +494,7 @@ int tdb_append(struct tdb_context *tdb, struct tdb_data new_dbuf; int ret; - off = find_and_lock(tdb, key, F_WRLCK, &h, &rec); + off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL); if (unlikely(off == TDB_OFF_ERR)) return -1; @@ -562,7 +562,7 @@ struct tdb_data tdb_fetch(struct tdb_context *tdb, struct tdb_data key) struct hash_info h; struct tdb_data ret; - off = find_and_lock(tdb, key, F_RDLCK, &h, &rec); + off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL); if (unlikely(off == TDB_OFF_ERR)) return tdb_null; @@ -585,7 +585,7 @@ int tdb_delete(struct tdb_context *tdb, struct tdb_data key) struct tdb_used_record rec; struct hash_info h; - off = find_and_lock(tdb, key, F_WRLCK, &h, &rec); + off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL); if (unlikely(off == TDB_OFF_ERR)) return -1; @@ -659,3 +659,21 @@ enum TDB_ERROR tdb_error(struct tdb_context *tdb) { return tdb->ecode; } + +const char *tdb_errorstr(struct tdb_context *tdb) +{ + /* Gcc warns if you miss a case in the switch, so use that. */ + switch (tdb->ecode) { + case TDB_SUCCESS: return "Success"; + case TDB_ERR_CORRUPT: return "Corrupt database"; + case TDB_ERR_IO: return "IO Error"; + case TDB_ERR_LOCK: return "Locking error"; + case TDB_ERR_OOM: return "Out of memory"; + case TDB_ERR_EXISTS: return "Record exists"; + case TDB_ERR_NESTING: return "Transaction already started"; + case TDB_ERR_EINVAL: return "Invalid parameter"; + case TDB_ERR_NOEXIST: return "Record does not exist"; + case TDB_ERR_RDONLY: return "write not permitted"; + } + return "Invalid error code"; +}