diff --git a/libc/src/stdio.cpp b/libc/src/stdio.cpp index d58cae21..0ce0b5fc 100644 --- a/libc/src/stdio.cpp +++ b/libc/src/stdio.cpp @@ -11,6 +11,13 @@ FILE* stdin = nullptr; FILE* stderr = nullptr; FILE* stdout = nullptr; +static const char* read_tmpdir() +{ + const char* tmpdir = getenv("TMPDIR"); + if (!tmpdir) return "/tmp"; + return tmpdir; +} + static int fopen_parse_mode(const char* mode) { int result = 0; @@ -477,8 +484,7 @@ extern "C" FILE* tmpfile() { - // FIXME: use /tmp as the directory when the tmpfs is mounted only there. - int fd = open("/", O_RDWR | O_TMPFILE, 0600); + int fd = open(read_tmpdir(), O_RDWR | O_TMPFILE, 0600); if (fd < 0) return nullptr; FILE* f = fdopen(fd, "w+b");