+
+TempDir::TempDir() {
+#if _DEFAULT_SOURCE || _BSD_SOURCE || _POSIX_C_SOURCE >= 200809L
+ char tmpl[] = "blank.XXXXXX";
+ const char *name = mkdtemp(tmpl);
+ if (!name) {
+ throw SysError("unable to create temporary directory");
+ }
+ path = name;
+#else
+ char name[L_tmpnam];
+ tmpnam(name);
+ constexpr int max_tries = 10;
+ int tries = 0;
+ while (!make_dirs(name) && tries < max_tries) {
+ tmpnam(name);
+ ++tries;
+ }
+ if (tries == max_tries) {
+ throw runtime_error("unable to create temporary directory");
+ }
+#endif
+ path = name;
+}
+
+TempDir::~TempDir() {
+ try {
+ remove_dir(path);
+ } catch (...) {
+ cerr << "warning: could not remove temp dir " << path << endl;
+ }
+}
+