File: check.cc

package info (click to toggle)
lmdbxx 0.9.14.1%2Bgit20160229.0b43ca8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 320 kB
  • sloc: cpp: 1,054; makefile: 68; xml: 17
file content (42 lines) | stat: -rw-r--r-- 1,185 bytes parent folder | download | duplicates (2)
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
/* This is free and unencumbered software released into the public domain. */

#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() {
  try {
    /* 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(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) {
    std::fprintf(stderr, "Failed with error: %s\n", error.what());
    return EXIT_FAILURE;
  }
}