diff --git a/test/osal-unix.cc b/test/osal-unix.cc index 7625e0f4..ab63db89 100644 --- a/test/osal-unix.cc +++ b/test/osal-unix.cc @@ -272,3 +272,14 @@ 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; +} diff --git a/test/osal-windows.cc b/test/osal-windows.cc index b1a8928c..5d2e51a6 100644 --- a/test/osal-windows.cc +++ b/test/osal-windows.cc @@ -305,3 +305,9 @@ void osal_udelay(unsigned us) { } bool osal_istty(int fd) { return _isatty(fd) != 0; } + +std::string osal_tempdir(void) { + char buf[MAX_PATH + 1]; + DWORD len = GetTempPathA(sizeof(buf), buf); + return std::string(buf, len); +} diff --git a/test/osal.h b/test/osal.h index f75aae38..c27282a6 100644 --- a/test/osal.h +++ b/test/osal.h @@ -31,6 +31,7 @@ int osal_delay(unsigned seconds); void osal_udelay(unsigned us); void osal_yield(void); bool osal_istty(int fd); +std::string osal_tempdir(void); #ifdef _MSC_VER #ifndef STDIN_FILENO