diff --git a/src/utils/io/tmpfile_posix.cc b/src/utils/io/tmpfile_posix.cc index 39d2af90b2..d75764d866 100644 --- a/src/utils/io/tmpfile_posix.cc +++ b/src/utils/io/tmpfile_posix.cc @@ -25,6 +25,11 @@ namespace utils { namespace { std::string TmpFilePath(std::string ext) { + char const* dir = getenv("TMPDIR"); + if (dir == nullptr) { + dir = "/tmp"; + } + // mkstemps requires an `int` for the file extension name but STL represents // size_t. Pre-C++20 there the behavior for unsigned-to-signed conversion // (when the source value exceeds the representable range) is implementation @@ -32,7 +37,7 @@ std::string TmpFilePath(std::string ext) { // enforce this here at runtime. TINT_ASSERT(Utils, ext.length() <= static_cast(std::numeric_limits::max())); - std::string name = "tint_XXXXXX" + ext; + std::string name = std::string(dir) + "/tint_XXXXXX" + ext; int file = mkstemps(&name[0], static_cast(ext.length())); if (file != -1) { close(file);