2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/utils/tempdir.hpp"
|
2020-02-16 13:47:21 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2020-06-14 18:28:39 +00:00
|
|
|
#include <cstdio>
|
2020-02-16 13:47:21 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
namespace webfuse_test
|
|
|
|
{
|
|
|
|
|
|
|
|
TempDir::TempDir(char const * prefix)
|
|
|
|
{
|
2020-06-14 18:28:39 +00:00
|
|
|
asprintf(&path_, "/tmp/%s_XXXXXX", prefix);
|
2020-02-16 13:47:21 +00:00
|
|
|
char * result = mkdtemp(path_);
|
|
|
|
if (NULL == result)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("unable to create temp dir");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TempDir::~TempDir()
|
|
|
|
{
|
|
|
|
rmdir(path_);
|
|
|
|
free(path_);
|
|
|
|
}
|
|
|
|
|
|
|
|
char const * TempDir::path()
|
|
|
|
{
|
|
|
|
return path_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|