summaryrefslogtreecommitdiff
path: root/source3/tdb
diff options
context:
space:
mode:
Diffstat (limited to 'source3/tdb')
-rw-r--r--source3/tdb/tdb.c6
-rw-r--r--source3/tdb/tdb.h3
-rw-r--r--source3/tdb/tdbtest.c6
-rw-r--r--source3/tdb/tdbtool.c10
4 files changed, 13 insertions, 12 deletions
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c
index feb925d978..c469436f75 100644
--- a/source3/tdb/tdb.c
+++ b/source3/tdb/tdb.c
@@ -220,7 +220,7 @@ static int tdb_oob(TDB_CONTEXT *tdb, tdb_off offset)
/* write a lump of data at a specified offset */
-static int tdb_write(TDB_CONTEXT *tdb, tdb_off offset, char *buf, tdb_len len)
+static int tdb_write(TDB_CONTEXT *tdb, tdb_off offset, const char *buf, tdb_len len)
{
if (tdb_oob(tdb, offset + len) != 0) {
/* oops - trying to write beyond the end of the database! */
@@ -674,7 +674,7 @@ int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key)
if fn is NULL then it is not called
a non-zero return value from fn() indicates that the traversal should stop
*/
-int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf))
+int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void* state), void* state)
{
int count = 0;
unsigned h;
@@ -712,7 +712,7 @@ int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB
dbuf.dsize = rec.data_len;
count++;
- if (fn && fn(tdb, key, dbuf) != 0) {
+ if (fn && fn(tdb, key, dbuf, state) != 0) {
/* they want us to stop traversing */
free(data);
tdb_unlock(tdb, BUCKET(h));
diff --git a/source3/tdb/tdb.h b/source3/tdb/tdb.h
index 8c066e7044..b24f08b648 100644
--- a/source3/tdb/tdb.h
+++ b/source3/tdb/tdb.h
@@ -72,6 +72,7 @@ int tdb_close(TDB_CONTEXT *tdb);
TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb);
TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key);
int tdb_traverse(TDB_CONTEXT *tdb,
- int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf));
+ int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state),
+ void *state);
int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key);
#endif
diff --git a/source3/tdb/tdbtest.c b/source3/tdb/tdbtest.c
index 581d8192d9..9728e59a01 100644
--- a/source3/tdb/tdbtest.c
+++ b/source3/tdb/tdbtest.c
@@ -168,7 +168,7 @@ static void addrec_gdbm(void)
free(d);
}
-static int traverse_fn(TDB_CONTEXT *db, TDB_DATA key, TDB_DATA dbuf)
+static int traverse_fn(TDB_CONTEXT *db, TDB_DATA key, TDB_DATA dbuf, void *state)
{
#if 0
printf("[%s] [%s]\n", key.dptr, dbuf.dptr);
@@ -208,8 +208,8 @@ int main(int argc, char *argv[])
compare_db();
- printf("traversed %d records\n", tdb_traverse(db, traverse_fn));
- printf("traversed %d records\n", tdb_traverse(db, traverse_fn));
+ printf("traversed %d records\n", tdb_traverse(db, traverse_fn, NULL));
+ printf("traversed %d records\n", tdb_traverse(db, traverse_fn, NULL));
tdb_close(db);
gdbm_close(gdbm);
diff --git a/source3/tdb/tdbtool.c b/source3/tdb/tdbtool.c
index b1c7e2774f..76b6259ef8 100644
--- a/source3/tdb/tdbtool.c
+++ b/source3/tdb/tdbtool.c
@@ -134,7 +134,7 @@ static void delete_tdb(void)
}
}
-static int print_rec(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
+static int print_rec(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
{
printf("%*.*s : %*.*s\n",
(int)key.dsize, (int)key.dsize, key.dptr,
@@ -144,7 +144,7 @@ static int print_rec(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
static int total_bytes;
-static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf)
+static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
{
total_bytes += dbuf.dsize;
return 0;
@@ -154,7 +154,7 @@ static void info_tdb(void)
{
int count;
total_bytes = 0;
- count = tdb_traverse(tdb, traverse_fn);
+ count = tdb_traverse(tdb, traverse_fn, NULL);
printf("%d records totalling %d bytes\n", count, total_bytes);
}
@@ -199,11 +199,11 @@ int main(int argc, char *argv[])
} else if (strcmp(tok,"show") == 0) {
show_tdb();
} else if (strcmp(tok,"erase") == 0) {
- tdb_traverse(tdb, tdb_delete);
+ tdb_traverse(tdb, tdb_delete, NULL);
} else if (strcmp(tok,"delete") == 0) {
delete_tdb();
} else if (strcmp(tok,"dump") == 0) {
- tdb_traverse(tdb, print_rec);
+ tdb_traverse(tdb, print_rec, NULL);
} else if (strcmp(tok,"info") == 0) {
info_tdb();
} else {