Skip to content

Commit 98e313f

Browse files
committed
test: Allow TempDir objects to be used as strings
Signed-off-by: Shaun Ruffell <[email protected]>
1 parent 954a072 commit 98e313f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/TempDir.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <unistd.h>
3131
#include <cstdlib>
32+
#include <cstring>
3233

3334
#include <iostream>
3435
#include <vector>
@@ -45,6 +46,9 @@ class TempDir
4546
void clear ();
4647
std::vector <std::string> file_names () const;
4748

49+
const std::string& name () const { return tmpName; };
50+
operator const std::string& () const { return name (); }
51+
4852
private:
4953
std::string tmpName {};
5054
std::string oldDir {};
@@ -53,9 +57,11 @@ class TempDir
5357
////////////////////////////////////////////////////////////////////////////////
5458
TempDir::TempDir ()
5559
{
60+
char template_name[PATH_MAX] = {'\0',};
61+
5662
oldDir = Directory::cwd ();
5763

58-
char template_name[] = "atomic_XXXXXX";
64+
strncpy (template_name, (oldDir + "/timew_test_XXXXXX").c_str (), sizeof (template_name) - 1);
5965
const char *cwd = ::mkdtemp (template_name);
6066
if (cwd == nullptr)
6167
{

0 commit comments

Comments
 (0)