Browse Source

tdb: add mktdb tool.

Rusty Russell 15 years ago
parent
commit
9cbb97f3ac
2 changed files with 30 additions and 1 deletions
  1. 1 1
      ccan/tdb/tools/Makefile
  2. 29 0
      ccan/tdb/tools/mktdb.c

+ 1 - 1
ccan/tdb/tools/Makefile

@@ -2,7 +2,7 @@ LDLIBS:=../../tdb.o ../../hash.o
 CFLAGS:=-I../../.. -Wall -O3 #-g -pg
 CFLAGS:=-I../../.. -Wall -O3 #-g -pg
 LDFLAGS:=-L../../..
 LDFLAGS:=-L../../..
 
 
-default: replay_trace tdbtorture tdbdump tdbtool starvation
+default: replay_trace tdbtorture tdbdump tdbtool starvation mktdb
 
 
 benchmark: replay_trace
 benchmark: replay_trace
 	@trap "rm -f /tmp/trace.$$$$" 0; for f in benchmarks/*.rz; do if runzip -k $$f -o /tmp/trace.$$$$ && echo -n "$$f": && ./replay_trace --quiet -n 5 replay.tdb /tmp/trace.$$$$ && rm /tmp/trace.$$$$; then rm -f /tmp/trace.$$$$; else exit 1; fi; done
 	@trap "rm -f /tmp/trace.$$$$" 0; for f in benchmarks/*.rz; do if runzip -k $$f -o /tmp/trace.$$$$ && echo -n "$$f": && ./replay_trace --quiet -n 5 replay.tdb /tmp/trace.$$$$ && rm /tmp/trace.$$$$; then rm -f /tmp/trace.$$$$; else exit 1; fi; done

+ 29 - 0
ccan/tdb/tools/mktdb.c

@@ -0,0 +1,29 @@
+#include <ccan/tdb/tdb.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <err.h>
+
+int main(int argc, char *argv[])
+{
+	unsigned int i, num_recs;
+	struct tdb_context *tdb;
+
+	if (argc != 3 || (num_recs = atoi(argv[2])) == 0)
+		errx(1, "Usage: mktdb <tdbfile> <numrecords>");
+
+	tdb = tdb_open(argv[1], 10007, TDB_DEFAULT, O_CREAT|O_TRUNC|O_RDWR, 0600);
+	if (!tdb)
+		err(1, "Opening %s", argv[1]);
+
+	for (i = 0; i < num_recs; i++) {
+		TDB_DATA d;
+
+		d.dptr = (void *)&i;
+		d.dsize = sizeof(i);
+		if (tdb_store(tdb, d, d, TDB_INSERT) != 0)
+			err(1, "Failed to store record %i", i);
+	}
+	printf("Done\n");
+	return 0;
+}