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!)
This commit is contained in:
parent
86e32035d7
commit
13f96cdcc9
@ -96,11 +96,14 @@ Dir Dir::tempDir(const std::string& templ)
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
const char* tempPath = ::getenv("TMPDIR");
|
const char* tempPath = ::getenv("TMPDIR");
|
||||||
if (!tempPath) {
|
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
|
// 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
|
// 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)) {
|
if (!mkdtemp(buf)) {
|
||||||
SG_LOG(SG_IO, SG_WARN, "mkdtemp failed:" << strerror(errno));
|
SG_LOG(SG_IO, SG_WARN, "mkdtemp failed:" << strerror(errno));
|
||||||
return Dir();
|
return Dir();
|
||||||
|
Loading…
Reference in New Issue
Block a user