mdbx-tests: refine temp-dir for unix.

This commit is contained in:
Leo Yuriev 2018-03-19 20:57:55 +03:00
parent 52283d8c44
commit 5872174db6

View File

@ -274,12 +274,20 @@ void osal_udelay(unsigned us) {
bool osal_istty(int fd) { return isatty(fd) == 1; } bool osal_istty(int fd) { return isatty(fd) == 1; }
std::string osal_tempdir(void) { std::string osal_tempdir(void) {
const char *tempdir = getenv("TEMPDIR"); const char *tempdir = getenv("TMPDIR");
if (!tempdir || *tempdir == '\0') if (!tempdir)
return (access("/dev/shm/", R_OK | W_OK | X_OK) == 0) ? "/dev/shm/" : ""; tempdir = getenv("TMP");
if (!tempdir)
std::string dir(tempdir); tempdir = getenv("TEMPDIR");
if (dir.at(dir.length() - 1) != '/') if (!tempdir)
dir.append("/"); tempdir = getenv("TEMP");
return dir; 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 "";
} }