tdb:tdbtest: use TEST_DATA_PREFIX for files
authorStefan Metzmacher <metze@samba.org>
Fri, 24 Dec 2010 10:54:03 +0000 (11:54 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 24 Dec 2010 16:31:06 +0000 (17:31 +0100)
metze

lib/tdb/tools/tdbtest.c

index 416bc50a5b073c07fad11c2d10a7a08fdb9253ae..44c78efda5cf27fa2e7ee85f330d37a0c006858d 100644 (file)
@@ -215,16 +215,38 @@ static void merge_test(void)
        tdb_delete(db, key);
 }
 
+static char *test_path(const char *filename)
+{
+       const char *prefix = getenv("TEST_DATA_PREFIX");
+
+       if (prefix) {
+               char *path = NULL;
+               int ret;
+
+               ret = asprintf(&path, "%s/%s", prefix, filename);
+               if (ret == -1) {
+                       return NULL;
+               }
+               return path;
+       }
+
+       return strdup(filename);
+}
+
  int main(int argc, const char *argv[])
 {
        int i, seed=0;
        int loops = 10000;
        int num_entries;
-       char test_gdbm[] = "test.gdbm";
+       char test_gdbm[1] = "test.gdbm";
+       char *test_tdb;
 
-       unlink("test.gdbm");
+       test_gdbm[0] = test_path("test.gdbm");
+       test_tdb = test_path("test.tdb");
 
-       db = tdb_open("test.tdb", 0, TDB_CLEAR_IF_FIRST, 
+       unlink(test_gdbm[0]);
+
+       db = tdb_open(test_tdb, 0, TDB_CLEAR_IF_FIRST,
                      O_RDWR | O_CREAT | O_TRUNC, 0600);
        gdbm = gdbm_open(test_gdbm, 512, GDBM_WRITER|GDBM_NEWDB|GDBM_FAST, 
                         0600, NULL);
@@ -261,5 +283,8 @@ static void merge_test(void)
        tdb_close(db);
        gdbm_close(gdbm);
 
+       free(test_gdbm[0]);
+       free(test_tdb);
+
        return 0;
 }