From: Rusty Russell Date: Tue, 1 Mar 2011 12:49:19 +0000 (+1030) Subject: tdb2: make error numbers negative. X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=74c15d72a2ddc484c771bc226134673409e9a40f;hp=b24f8e2ae5ac22fc2e5dbfebebf9c5fa2f338588 tdb2: make error numbers negative. This prepares us for changing function returns over. --- diff --git a/ccan/tdb2/tdb2.h b/ccan/tdb2/tdb2.h index 23f57f84..3e02c803 100644 --- a/ccan/tdb2/tdb2.h +++ b/ccan/tdb2/tdb2.h @@ -96,6 +96,24 @@ typedef struct tdb_data { size_t dsize; } TDB_DATA; +/** + * enum TDB_ERROR - error returns for TDB + * + * See Also: + * tdb_errorstr() + */ +enum TDB_ERROR { + TDB_SUCCESS = 0, /* No error. */ + TDB_ERR_CORRUPT = -1, /* We read the db, and it was bogus. */ + TDB_ERR_IO = -2, /* We couldn't read/write the db. */ + TDB_ERR_LOCK = -3, /* Locking failed. */ + TDB_ERR_OOM = -4, /* Out of Memory. */ + TDB_ERR_EXISTS = -5, /* The key already exists. */ + TDB_ERR_NOEXIST = -6, /* The key does not exist. */ + TDB_ERR_EINVAL = -7, /* You're using it wrong. */ + TDB_ERR_RDONLY = -8 /* The database is read-only. */ +}; + /** * tdb_store - store a key/value pair in a tdb. * @tdb: the tdb context returned from tdb_open() @@ -142,17 +160,6 @@ struct tdb_data tdb_fetch(struct tdb_context *tdb, struct tdb_data key); * See Also: * tdb_error(), tdb_errorstr() */ -enum TDB_ERROR { - TDB_SUCCESS=0, /* No error. */ - TDB_ERR_CORRUPT, /* We read the db, and it was bogus. */ - TDB_ERR_IO, /* We couldn't read/write the db. */ - TDB_ERR_LOCK, /* Locking failed. */ - TDB_ERR_OOM, /* Out of Memory. */ - TDB_ERR_EXISTS, /* The key already exists. */ - TDB_ERR_NOEXIST, /* The key does not exist. */ - TDB_ERR_EINVAL, /* You're using it wrong. */ - TDB_ERR_RDONLY /* The database is read-only. */ -}; /** * tdb_error - fetch the last error value from the tdb. diff --git a/ccan/tdb2/test/run-tdb_errorstr.c b/ccan/tdb2/test/run-tdb_errorstr.c index 15e3b184..e8600e7f 100644 --- a/ccan/tdb2/test/run-tdb_errorstr.c +++ b/ccan/tdb2/test/run-tdb_errorstr.c @@ -11,13 +11,13 @@ int main(int argc, char *argv[]) { struct tdb_context *tdb; - plan_tests(1 + TDB_ERR_RDONLY + 2); + plan_tests(1 + TDB_ERR_RDONLY*-1 + 2); tdb = tdb_open("run-tdb_errorstr.tdb", TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0600, NULL); ok1(tdb); if (tdb) { enum TDB_ERROR err; - for (err = TDB_SUCCESS; err <= TDB_ERR_RDONLY; err++) { + for (err = TDB_SUCCESS; err >= TDB_ERR_RDONLY; err--) { tdb->ecode = err; switch (err) { case TDB_SUCCESS: