From 5872174db618361213b8995c857acf5674de8c88 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Mon, 19 Mar 2018 20:57:55 +0300 Subject: [PATCH] mdbx-tests: refine temp-dir for unix. --- test/osal-unix.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/osal-unix.cc b/test/osal-unix.cc index ab63db89..8132e267 100644 --- a/test/osal-unix.cc +++ b/test/osal-unix.cc @@ -274,12 +274,20 @@ void osal_udelay(unsigned us) { bool osal_istty(int fd) { return isatty(fd) == 1; } std::string osal_tempdir(void) { - const char *tempdir = getenv("TEMPDIR"); - if (!tempdir || *tempdir == '\0') - return (access("/dev/shm/", R_OK | W_OK | X_OK) == 0) ? "/dev/shm/" : ""; - - std::string dir(tempdir); - if (dir.at(dir.length() - 1) != '/') - dir.append("/"); - return dir; + const char *tempdir = getenv("TMPDIR"); + if (!tempdir) + tempdir = getenv("TMP"); + if (!tempdir) + tempdir = getenv("TEMPDIR"); + if (!tempdir) + tempdir = getenv("TEMP"); + if (tempdir) { + std::string dir(tempdir); + if (!dir.empty() && dir.at(dir.length() - 1) != '/') + dir.append("/"); + return dir; + } + if (access("/dev/shm/", R_OK | W_OK | X_OK) == 0) + return "/dev/shm/"; + return ""; }