forked from pz4kybsvg/Conception
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
825 B
38 lines
825 B
#include "drake/common/temp_directory.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cstdlib>
|
|
#include <filesystem>
|
|
|
|
#include "drake/common/drake_throw.h"
|
|
|
|
namespace drake {
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
std::string temp_directory() {
|
|
fs::path path;
|
|
|
|
const char* tmpdir = nullptr;
|
|
(tmpdir = std::getenv("TEST_TMPDIR")) || (tmpdir = std::getenv("TMPDIR")) ||
|
|
(tmpdir = "/tmp");
|
|
|
|
fs::path path_template(tmpdir);
|
|
path_template.append("robotlocomotion_drake_XXXXXX");
|
|
|
|
std::string path_template_str = path_template.string();
|
|
const char* dtemp = ::mkdtemp(&path_template_str[0]);
|
|
DRAKE_THROW_UNLESS(dtemp != nullptr);
|
|
|
|
path = dtemp;
|
|
|
|
DRAKE_THROW_UNLESS(fs::is_directory(path));
|
|
std::string path_string = path.string();
|
|
DRAKE_DEMAND(path_string.back() != '/');
|
|
|
|
return path_string;
|
|
}
|
|
|
|
} // namespace drake
|