From 13f96cdcc9f686d900770bb24215284f3774bec8 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sat, 3 Mar 2012 17:06:51 +0100 Subject: [PATCH] Dir::tempDir not working on some systems. Only worked when TMPDIR environment variable had a trailing slash (i.e. "/tmp/" worked, but not "/tmp"). (Problem shown by simgear's "test suite". It's good to have tests!) --- simgear/misc/sg_dir.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/simgear/misc/sg_dir.cxx b/simgear/misc/sg_dir.cxx index 1514c950..a9969e07 100644 --- a/simgear/misc/sg_dir.cxx +++ b/simgear/misc/sg_dir.cxx @@ -96,11 +96,14 @@ Dir Dir::tempDir(const std::string& templ) char buf[1024]; const char* tempPath = ::getenv("TMPDIR"); if (!tempPath) { - tempPath = "/tmp/"; + tempPath = "/tmp"; } + SGPath p(tempPath); + p.append(templ); // Mac OS-X / BSD manual says any number of 'X's, but GLibc manual // says exactly six, so that's what I'm going with - ::snprintf(buf, 1024, "%s%s-XXXXXX", tempPath, templ.c_str()); + p.concat("-XXXXXX"); + ::snprintf(buf, 1024, "%s", p.c_str()); if (!mkdtemp(buf)) { SG_LOG(SG_IO, SG_WARN, "mkdtemp failed:" << strerror(errno)); return Dir(); -- 2.39.5