Skip to content

Commit

Permalink
tests: replace tmpnam() with mkdtemp() in implementation of TempDir
Browse files Browse the repository at this point in the history
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 <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
wkozaczuk authored and nyh committed Dec 9, 2019
1 parent 15e689d commit 6c3cebc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/tst-fs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/fstream.hpp>
Expand All @@ -22,8 +23,13 @@ typedef boost::format fmt;
class TempDir : public fs::path
{
public:
TempDir() : fs::path(tmpnam(NULL)) {
fs::create_directories(*this);
TempDir() : fs::path() {
char path[64] = "/tmp/dirXXXXXX";
auto dir_path = mkdtemp(path);
if (!dir_path) {
throw std::system_error(std::error_code(errno, std::system_category()), "error creating temp directory");
}
*this += dir_path;
}

virtual ~TempDir() {
Expand Down

0 comments on commit 6c3cebc

Please sign in to comment.