Skip to content

Commit 6c3cebc

Browse files
wkozaczuknyh
authored andcommitted
tests: replace tmpnam() with mkdtemp() in implementation of TempDir
This should be the last patch addressing compiler warnings in unit tests as reported by the issue #976. Refs #976 Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com> Message-Id: <20191209042729.21316-1-jwkozaczuk@gmail.com>
1 parent 15e689d commit 6c3cebc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/tst-fs.hh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <sys/types.h>
1212
#include <sys/stat.h>
1313
#include <unistd.h>
14+
#include <stdlib.h>
1415
#include <boost/filesystem.hpp>
1516
#include <boost/test/unit_test.hpp>
1617
#include <boost/filesystem/fstream.hpp>
@@ -22,8 +23,13 @@ typedef boost::format fmt;
2223
class TempDir : public fs::path
2324
{
2425
public:
25-
TempDir() : fs::path(tmpnam(NULL)) {
26-
fs::create_directories(*this);
26+
TempDir() : fs::path() {
27+
char path[64] = "/tmp/dirXXXXXX";
28+
auto dir_path = mkdtemp(path);
29+
if (!dir_path) {
30+
throw std::system_error(std::error_code(errno, std::system_category()), "error creating temp directory");
31+
}
32+
*this += dir_path;
2733
}
2834

2935
virtual ~TempDir() {

0 commit comments

Comments
 (0)