diff options
author | Andrew Bartlett <abartlet@samba.org> | 2003-01-12 12:23:37 +0000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2003-01-12 12:23:37 +0000 |
commit | fd88966c470ec125476c9c8d4cb68678ac249e47 (patch) | |
tree | 95e1c2ec68d443cf4d5eee1686251f79791eae9d | |
parent | e009abb20a60a59f5923915b7c9e46e5244337de (diff) | |
download | samba-fd88966c470ec125476c9c8d4cb68678ac249e47.tar.gz samba-fd88966c470ec125476c9c8d4cb68678ac249e47.tar.bz2 samba-fd88966c470ec125476c9c8d4cb68678ac249e47.zip |
Keep all the const warnings in one place, by adding a utility function to
make the TDB_DATA.
Andrew Bartlett
(This used to be commit f087fe546fd0c943dec022c657f849803f4b807e)
-rw-r--r-- | source3/tdb/tdbutil.c | 75 |
1 files changed, 31 insertions, 44 deletions
diff --git a/source3/tdb/tdbutil.c b/source3/tdb/tdbutil.c index d66a0a4d73..da155de4d7 100644 --- a/source3/tdb/tdbutil.c +++ b/source3/tdb/tdbutil.c @@ -35,6 +35,18 @@ static void gotalarm_sig(void) gotalarm = 1; } +/*************************************************************** + Make a TDB_DATA and keep the const warning in one place +****************************************************************/ + +static TDB_DATA make_tdb_data(const char *dptr, size_t dsize) +{ + TDB_DATA ret; + ret.dptr = dptr; + ret.dsize = dsize; + return ret; +} + /**************************************************************************** Lock a chain with timeout (in seconds). ****************************************************************************/ @@ -79,10 +91,7 @@ static int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int tdb_lock_bystring(TDB_CONTEXT *tdb, const char *keyval, unsigned int timeout) { - TDB_DATA key; - - key.dptr = keyval; - key.dsize = strlen(keyval)+1; + TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); return tdb_chainlock_with_timeout(tdb, key, timeout, F_WRLCK); } @@ -93,11 +102,8 @@ int tdb_lock_bystring(TDB_CONTEXT *tdb, const char *keyval, unsigned int timeout void tdb_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval) { - TDB_DATA key; + TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); - key.dptr = keyval; - key.dsize = strlen(keyval)+1; - tdb_chainunlock(tdb, key); } @@ -107,10 +113,7 @@ void tdb_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval) int tdb_read_lock_bystring(TDB_CONTEXT *tdb, const char *keyval, unsigned int timeout) { - TDB_DATA key; - - key.dptr = keyval; - key.dsize = strlen(keyval)+1; + TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); return tdb_chainlock_with_timeout(tdb, key, timeout, F_RDLCK); } @@ -121,10 +124,7 @@ int tdb_read_lock_bystring(TDB_CONTEXT *tdb, const char *keyval, unsigned int ti void tdb_read_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval) { - TDB_DATA key; - - key.dptr = keyval; - key.dsize = strlen(keyval)+1; + TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); tdb_chainunlock_read(tdb, key); } @@ -137,11 +137,10 @@ void tdb_read_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval) int32 tdb_fetch_int32_byblob(TDB_CONTEXT *tdb, const char *keyval, size_t len) { - TDB_DATA key, data; + TDB_DATA key = make_tdb_data(keyval, len); + TDB_DATA data; int32 ret; - key.dptr = keyval; - key.dsize = len; data = tdb_fetch(tdb, key); if (!data.dptr || data.dsize != sizeof(int32)) { SAFE_FREE(data.dptr); @@ -170,11 +169,10 @@ int32 tdb_fetch_int32(TDB_CONTEXT *tdb, const char *keystr) int tdb_store_int32_byblob(TDB_CONTEXT *tdb, const char *keystr, size_t len, int32 v) { - TDB_DATA key, data; + TDB_DATA key = make_tdb_data(keystr, len); + TDB_DATA data; int32 v_store; - key.dptr = keystr; - key.dsize = len; SIVAL(&v_store,0,v); data.dptr = (void *)&v_store; data.dsize = sizeof(int32); @@ -199,10 +197,9 @@ int tdb_store_int32(TDB_CONTEXT *tdb, const char *keystr, int32 v) BOOL tdb_fetch_uint32_byblob(TDB_CONTEXT *tdb, const char *keyval, size_t len, uint32 *value) { - TDB_DATA key, data; + TDB_DATA key = make_tdb_data(keyval, len); + TDB_DATA data; - key.dptr = keyval; - key.dsize = len; data = tdb_fetch(tdb, key); if (!data.dptr || data.dsize != sizeof(uint32)) { SAFE_FREE(data.dptr); @@ -231,12 +228,11 @@ BOOL tdb_fetch_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 *value) BOOL tdb_store_uint32_byblob(TDB_CONTEXT *tdb, const char *keystr, size_t len, uint32 value) { - TDB_DATA key, data; + TDB_DATA key = make_tdb_data(keystr, len); + TDB_DATA data; uint32 v_store; BOOL ret = True; - key.dptr = keystr; - key.dsize = len; SIVAL(&v_store, 0, value); data.dptr = (void *)&v_store; data.dsize = sizeof(uint32); @@ -263,12 +259,9 @@ BOOL tdb_store_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 value) int tdb_store_by_string(TDB_CONTEXT *tdb, const char *keystr, TDB_DATA data, int flags) { - TDB_DATA key; - - key.dptr = keystr; - key.dsize = strlen(keystr) + 1; - - return tdb_store(tdb, key, data, flags); + TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); + + return tdb_store(tdb, key, data, flags); } /**************************************************************************** @@ -278,12 +271,9 @@ int tdb_store_by_string(TDB_CONTEXT *tdb, const char *keystr, TDB_DATA data, int TDB_DATA tdb_fetch_by_string(TDB_CONTEXT *tdb, const char *keystr) { - TDB_DATA key; + TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); - key.dptr = keystr; - key.dsize = strlen(keystr) + 1; - - return tdb_fetch(tdb, key); + return tdb_fetch(tdb, key); } /**************************************************************************** @@ -292,12 +282,9 @@ TDB_DATA tdb_fetch_by_string(TDB_CONTEXT *tdb, const char *keystr) int tdb_delete_by_string(TDB_CONTEXT *tdb, const char *keystr) { - TDB_DATA key; - - key.dptr = keystr; - key.dsize = strlen(keystr) + 1; + TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); - return tdb_delete(tdb, key); + return tdb_delete(tdb, key); } /**************************************************************************** |