Description: create temporary directory Use a unique temporary directory for the test, and clean it up when done. Author: Hubert Chathi Forwarded: No --- --- lmdbxx-0.9.14.1+git20160228.0b43ca8.orig/check.cc +++ lmdbxx-0.9.14.1+git20160228.0b43ca8/check.cc @@ -2,6 +2,9 @@ #include /* for std::*printf() */ #include /* for EXIT_FAILURE, EXIT_SUCCESS */ +#include /* for std::errno */ +#include /* for std::error */ +#include /* for unlink and rmdir */ #include int main() { @@ -9,14 +12,27 @@ int main() { /* Create the LMDB environment: */ auto env = lmdb::env::create(); + char tmpdir[] = "/tmp/check.XXXXXX"; + if (!mkdtemp(tmpdir)) { + std::fprintf(stderr, "Unable to create temporary directory: %s\n", std::strerror(errno)); + return EXIT_FAILURE; + } /* Open the LMDB environment: */ - env.open("/tmp"); + env.open(tmpdir); /* Begin the LMDB transaction: */ auto txn = lmdb::txn::begin(env); // TODO + /* clean up */ + char filename[30]; // enough room for tmpdir + filename + std::sprintf(filename, "%s/data.mdb", tmpdir); + unlink(filename); + std::sprintf(filename, "%s/lock.mdb", tmpdir); + unlink(filename); + rmdir(tmpdir); + return EXIT_SUCCESS; } catch (const lmdb::error& error) {