summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2010-03-14 13:49:58 +0100
committerVolker Lendecke <vl@samba.org>2010-03-14 17:42:49 +0100
commit2111fe5255c1a76c267bbd0986a9f4566e6a68f9 (patch)
treee25c743b08efcdb5eee75f16d002b5d698d91423
parent6c00a3db24808333df734dde15064d01b32dbf45 (diff)
downloadsamba-2111fe5255c1a76c267bbd0986a9f4566e6a68f9.tar.gz
samba-2111fe5255c1a76c267bbd0986a9f4566e6a68f9.tar.bz2
samba-2111fe5255c1a76c267bbd0986a9f4566e6a68f9.zip
s3: Use a switch to implement map_nt_error_from_tdb
First, this immediately gave me the warning that TDB_ERR_NESTING was not covered and second, this saved 48 bytes in the .o :-)
-rw-r--r--source3/lib/util_tdb.c77
1 files changed, 47 insertions, 30 deletions
diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c
index fe2f231a71..aef4a7dec3 100644
--- a/source3/lib/util_tdb.c
+++ b/source3/lib/util_tdb.c
@@ -642,39 +642,56 @@ fail:
NTSTATUS map_nt_error_from_tdb(enum TDB_ERROR err)
{
- struct { enum TDB_ERROR err; NTSTATUS status; } map[] =
- { { TDB_SUCCESS, NT_STATUS_OK },
- { TDB_ERR_CORRUPT, NT_STATUS_INTERNAL_DB_CORRUPTION },
- { TDB_ERR_IO, NT_STATUS_UNEXPECTED_IO_ERROR },
- { TDB_ERR_OOM, NT_STATUS_NO_MEMORY },
- { TDB_ERR_EXISTS, NT_STATUS_OBJECT_NAME_COLLISION },
-
- /*
- * TDB_ERR_LOCK is very broad, we could for example
- * distinguish between fcntl locks and invalid lock
- * sequences. So NT_STATUS_FILE_LOCK_CONFLICT is a
- * compromise.
- */
- { TDB_ERR_LOCK, NT_STATUS_FILE_LOCK_CONFLICT },
- /*
- * The next two ones in the enum are not actually used
- */
- { TDB_ERR_NOLOCK, NT_STATUS_FILE_LOCK_CONFLICT },
- { TDB_ERR_LOCK_TIMEOUT, NT_STATUS_FILE_LOCK_CONFLICT },
- { TDB_ERR_NOEXIST, NT_STATUS_NOT_FOUND },
- { TDB_ERR_EINVAL, NT_STATUS_INVALID_PARAMETER },
- { TDB_ERR_RDONLY, NT_STATUS_ACCESS_DENIED }
- };
+ NTSTATUS result = NT_STATUS_INTERNAL_ERROR;
- int i;
+ switch (err) {
+ case TDB_SUCCESS:
+ result = NT_STATUS_OK;
+ break;
+ case TDB_ERR_CORRUPT:
+ result = NT_STATUS_INTERNAL_DB_CORRUPTION;
+ break;
+ case TDB_ERR_IO:
+ result = NT_STATUS_UNEXPECTED_IO_ERROR;
+ break;
+ case TDB_ERR_OOM:
+ result = NT_STATUS_NO_MEMORY;
+ break;
+ case TDB_ERR_EXISTS:
+ result = NT_STATUS_OBJECT_NAME_COLLISION;
+ break;
- for (i=0; i < sizeof(map) / sizeof(map[0]); i++) {
- if (err == map[i].err) {
- return map[i].status;
- }
- }
+ case TDB_ERR_LOCK:
+ /*
+ * TDB_ERR_LOCK is very broad, we could for example
+ * distinguish between fcntl locks and invalid lock
+ * sequences. So NT_STATUS_FILE_LOCK_CONFLICT is a
+ * compromise.
+ */
+ result = NT_STATUS_FILE_LOCK_CONFLICT;
+ break;
- return NT_STATUS_INTERNAL_ERROR;
+ case TDB_ERR_NOLOCK:
+ case TDB_ERR_LOCK_TIMEOUT:
+ /*
+ * These two ones in the enum are not actually used
+ */
+ result = NT_STATUS_FILE_LOCK_CONFLICT;
+ break;
+ case TDB_ERR_NOEXIST:
+ result = NT_STATUS_NOT_FOUND;
+ break;
+ case TDB_ERR_EINVAL:
+ result = NT_STATUS_INVALID_PARAMETER;
+ break;
+ case TDB_ERR_RDONLY:
+ result = NT_STATUS_ACCESS_DENIED;
+ break;
+ case TDB_ERR_NESTING:
+ result = NT_STATUS_INTERNAL_ERROR;
+ break;
+ };
+ return result;
}
int tdb_data_cmp(TDB_DATA t1, TDB_DATA t2)