From 6c3cebcfc9521b96f3aff8d9934e0c1e6e461780 Mon Sep 17 00:00:00 2001 From: Waldemar Kozaczuk Date: Sun, 8 Dec 2019 23:27:29 -0500 Subject: [PATCH] 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 Message-Id: <20191209042729.21316-1-jwkozaczuk@gmail.com> --- tests/tst-fs.hh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/tst-fs.hh b/tests/tst-fs.hh index 6d5321ef4f..6330dea2d9 100644 --- a/tests/tst-fs.hh +++ b/tests/tst-fs.hh @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -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() {