diff options
author | Jeremy Allison <jra@samba.org> | 2000-04-28 02:06:19 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2000-04-28 02:06:19 +0000 |
commit | d69e4c6a48746459f973144393529b1f40680d2f (patch) | |
tree | c5e9681c6d4726ec6b522eb00f2de0ca3bcd6719 /source | |
parent | b812f09ba8ef074c9ff0747ea03a1e33f1ebbe71 (diff) | |
download | samba-d69e4c6a48746459f973144393529b1f40680d2f.tar.gz samba-d69e4c6a48746459f973144393529b1f40680d2f.tar.xz samba-d69e4c6a48746459f973144393529b1f40680d2f.zip |
Added tdb_get/set_int_byblob, which takes a size_t len and then implemented
the tdb_get/set_int string functions in terms of them. Will be useful in storing
POSIX pending close records (which are ints but indexed by dev/inode pairs).
Jeremy.
Diffstat (limited to 'source')
-rw-r--r-- | source/include/proto.h | 2 | ||||
-rw-r--r-- | source/tdb/tdb.c | 26 |
2 files changed, 21 insertions, 7 deletions
diff --git a/source/include/proto.h b/source/include/proto.h index f9479532fa2..1d952da4ee4 100644 --- a/source/include/proto.h +++ b/source/include/proto.h @@ -3469,7 +3469,9 @@ int tdb_writelock(TDB_CONTEXT *tdb); int tdb_writeunlock(TDB_CONTEXT *tdb); int tdb_lockchain(TDB_CONTEXT *tdb, TDB_DATA key); int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key); +int tdb_get_int_byblob(TDB_CONTEXT *tdb, char *keyval, size_t len); int tdb_get_int(TDB_CONTEXT *tdb, char *keystr); +int tdb_store_int_byblob(TDB_CONTEXT *tdb, char *keystr, size_t len, int v); int tdb_store_int(TDB_CONTEXT *tdb, char *keystr, int v); /*The following definitions come from utils/nbio.c */ diff --git a/source/tdb/tdb.c b/source/tdb/tdb.c index 3b85b712170..e884bb34b94 100644 --- a/source/tdb/tdb.c +++ b/source/tdb/tdb.c @@ -1313,14 +1313,15 @@ int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key) simple string/value pairs in a tdb. They also serve as examples */ -/* fetch a value by string key, return -1 if not found */ -int tdb_get_int(TDB_CONTEXT *tdb, char *keystr) +/* fetch a value by a arbitrary blob key, return -1 if not found */ + +int tdb_get_int_byblob(TDB_CONTEXT *tdb, char *keyval, size_t len) { TDB_DATA key, data; int ret; - key.dptr = keystr; - key.dsize = strlen(keystr); + key.dptr = keyval; + key.dsize = len; data = tdb_fetch(tdb, key); if (!data.dptr || data.dsize != sizeof(int)) return -1; @@ -1328,16 +1329,27 @@ int tdb_get_int(TDB_CONTEXT *tdb, char *keystr) free(data.dptr); return ret; } +/* fetch a value by string key, return -1 if not found */ +int tdb_get_int(TDB_CONTEXT *tdb, char *keystr) +{ + return tdb_get_int_byblob(tdb, keystr, strlen(keystr)); +} -/* store a value by string key, return 0 on success, -1 on failure */ -int tdb_store_int(TDB_CONTEXT *tdb, char *keystr, int v) +/* store a value by an arbitary blob key, return 0 on success, -1 on failure */ +int tdb_store_int_byblob(TDB_CONTEXT *tdb, char *keystr, size_t len, int v) { TDB_DATA key, data; key.dptr = keystr; - key.dsize = strlen(keystr); + key.dsize = len; data.dptr = (void *)&v; data.dsize = sizeof(int); return tdb_store(tdb, key, data, TDB_REPLACE); } + +/* store a value by string key, return 0 on success, -1 on failure */ +int tdb_store_int(TDB_CONTEXT *tdb, char *keystr, int v) +{ + return tdb_store_int_byblob(tdb, keystr, strlen(keystr), v); +} |