new_off = alloc(tdb, key.dsize, dbuf.dsize, h->h, TDB_USED_MAGIC,
growing);
if (TDB_OFF_IS_ERR(new_off)) {
- return new_off;
+ return TDB_OFF_TO_ERR(new_off);
}
/* We didn't like the existing one: remove it. */
off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
if (TDB_OFF_IS_ERR(off)) {
- return tdb->last_error = off;
+ return tdb->last_error = TDB_OFF_TO_ERR(off);
}
/* Now we have lock on this hash bucket. */
off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
if (TDB_OFF_IS_ERR(off)) {
- return tdb->last_error = off;
+ return tdb->last_error = TDB_OFF_TO_ERR(off);
}
if (off) {
off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL);
if (TDB_OFF_IS_ERR(off)) {
- return tdb->last_error = off;
+ return tdb->last_error = TDB_OFF_TO_ERR(off);
}
if (!off) {
off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL);
if (TDB_OFF_IS_ERR(off)) {
- tdb->last_error = off;
+ tdb->last_error = TDB_OFF_TO_ERR(off);
return false;
}
tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range, F_RDLCK);
off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
if (TDB_OFF_IS_ERR(off)) {
- return tdb->last_error = off;
+ return tdb->last_error = TDB_OFF_TO_ERR(off);
}
if (!off) {
const char *tdb_errorstr(enum TDB_ERROR ecode)
{
/* Gcc warns if you miss a case in the switch, so use that. */
- switch (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_EINVAL: return "Invalid parameter";
- case TDB_ERR_NOEXIST: return "Record does not exist";
- case TDB_ERR_RDONLY: return "write not permitted";
+ switch (TDB_ERR_TO_OFF(ecode)) {
+ case TDB_ERR_TO_OFF(TDB_SUCCESS): return "Success";
+ case TDB_ERR_TO_OFF(TDB_ERR_CORRUPT): return "Corrupt database";
+ case TDB_ERR_TO_OFF(TDB_ERR_IO): return "IO Error";
+ case TDB_ERR_TO_OFF(TDB_ERR_LOCK): return "Locking error";
+ case TDB_ERR_TO_OFF(TDB_ERR_OOM): return "Out of memory";
+ case TDB_ERR_TO_OFF(TDB_ERR_EXISTS): return "Record exists";
+ case TDB_ERR_TO_OFF(TDB_ERR_EINVAL): return "Invalid parameter";
+ case TDB_ERR_TO_OFF(TDB_ERR_NOEXIST): return "Record does not exist";
+ case TDB_ERR_TO_OFF(TDB_ERR_RDONLY): return "write not permitted";
}
return "Invalid error code";
}
off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL);
if (TDB_OFF_IS_ERR(off)) {
- return tdb->last_error = off;
+ return tdb->last_error = TDB_OFF_TO_ERR(off);
}
if (!off) {
val = tdb1_get_seqnum(tdb);
if (tdb->last_error != TDB_SUCCESS)
- return tdb->last_error;
+ return TDB_ERR_TO_OFF(tdb->last_error);
else
return val;
}
off = tdb_read_off(tdb, offsetof(struct tdb_header, seqnum));
if (TDB_OFF_IS_ERR(off))
- tdb->last_error = off;
+ tdb->last_error = TDB_OFF_TO_ERR(off);
else
tdb->last_error = TDB_SUCCESS;
return off;