check if tmp is null

This commit is contained in:
Patrick Brosi 2019-05-14 00:46:53 +02:00
parent 347badf770
commit df1ba83a53

View file

@ -119,7 +119,7 @@ inline std::string getHomeDir() {
inline std::string getTmpDir() { inline std::string getTmpDir() {
// first, check if an env variable is set // first, check if an env variable is set
const char* tmpdir = getenv("TMPDIR"); const char* tmpdir = getenv("TMPDIR");
if (std::strlen(tmpdir)) return std::string(tmpdir); if (tmpdir && std::strlen(tmpdir)) return std::string(tmpdir);
// second, check if /tmp is writable // second, check if /tmp is writable
if (access("/tmp/", W_OK) == 0) return "/tmp"; if (access("/tmp/", W_OK) == 0) return "/tmp";