37 result = std::filesystem::temp_directory_path().string();
39 catch(
const std::filesystem::filesystem_error &)
44 std::string prefixed_name_template =
"/tmp/";
45 const char *TMPDIR_env = getenv(
"TMPDIR");
46 if(TMPDIR_env !=
nullptr)
47 prefixed_name_template = TMPDIR_env;
48 if(*prefixed_name_template.rbegin() !=
'/')
49 prefixed_name_template +=
'/';
50 prefixed_name_template += name_template;
53 prefixed_name_template.begin(), prefixed_name_template.end());
55 const char *td = mkdtemp(t.data());
60 char *wd = realpath(td,
nullptr);
64 std::string(
"realpath failed: ") + std::strerror(errno));
66 result = std::string(wd);