diff options
author | Andrew Tridgell <tridge@samba.org> | 2000-04-16 06:23:11 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2000-04-16 06:23:11 +0000 |
commit | cc65914cdcceb1fdeeb5d6ec1cf2ea2f865c5092 (patch) | |
tree | 84ee101ae1744ecbfbf9411dc3fb1aceb71897e6 /source/tdb | |
parent | d870542c2884510bd45fd5b54ff2157434d53f4c (diff) | |
download | samba-cc65914cdcceb1fdeeb5d6ec1cf2ea2f865c5092.tar.gz samba-cc65914cdcceb1fdeeb5d6ec1cf2ea2f865c5092.tar.xz samba-cc65914cdcceb1fdeeb5d6ec1cf2ea2f865c5092.zip |
added tdb_get_int() and tdb_store_int()
they are very useful for database versioning
Diffstat (limited to 'source/tdb')
-rw-r--r-- | source/tdb/tdb.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/tdb/tdb.c b/source/tdb/tdb.c index 388f4f419fe..7a0c566f41a 100644 --- a/source/tdb/tdb.c +++ b/source/tdb/tdb.c @@ -1286,3 +1286,37 @@ int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key) return tdb_unlock(tdb, BUCKET(tdb_hash(&key))); } + + +/* these two utility functions provide convent routines for storing + 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) +{ + TDB_DATA key, data; + int ret; + + key.dptr = keystr; + key.dsize = strlen(keystr); + data = tdb_fetch(tdb, key); + if (!data.dptr || data.dsize != sizeof(int)) return -1; + + memcpy(&ret, data.dptr, sizeof(int)); + free(data.dptr); + return ret; +} + +/* store a value by string key, return 0 on success, -1 on failure */ +int tdb_store_int(TDB_CONTEXT *tdb, char *keystr, int v) +{ + TDB_DATA key, data; + + key.dptr = keystr; + key.dsize = strlen(keystr); + data.dptr = (void *)&v; + data.dsize = sizeof(int); + + return tdb_store(tdb, key, data, TDB_REPLACE); +} |