summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2000-04-16 06:23:11 +0000
committerAndrew Tridgell <tridge@samba.org>2000-04-16 06:23:11 +0000
commit4367a3edfb6bd46927ca9a981568584975347a56 (patch)
tree7ae9b7e2b13b1a3fb6e5b91b842ff92107a65352
parent54de56a1be8ede7476c741cd1631ad1ac8107fcc (diff)
downloadsamba-4367a3edfb6bd46927ca9a981568584975347a56.tar.gz
samba-4367a3edfb6bd46927ca9a981568584975347a56.tar.bz2
samba-4367a3edfb6bd46927ca9a981568584975347a56.zip
added tdb_get_int() and tdb_store_int()
they are very useful for database versioning (This used to be commit cc65914cdcceb1fdeeb5d6ec1cf2ea2f865c5092)
-rw-r--r--source3/tdb/tdb.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c
index 388f4f419f..7a0c566f41 100644
--- a/source3/tdb/tdb.c
+++ b/source3/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);
+}