1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
Description: create temporary directory
Use a unique temporary directory for the test, and clean it up when done.
Author: Hubert Chathi <uhoreg@debian.org>
---
--- lmdbxx-0.9.14.1+git20160228.0b43ca8.orig/check.cc
+++ lmdbxx-0.9.14.1+git20160228.0b43ca8/check.cc
@@ -2,6 +2,9 @@
#include <cstdio> /* for std::*printf() */
#include <cstdlib> /* for EXIT_FAILURE, EXIT_SUCCESS */
+#include <cerrno> /* for std::errno */
+#include <cstring> /* for std::error */
+#include <unistd.h> /* for unlink and rmdir */
#include <lmdb++.h>
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) {
|