libc: Make tmpfile() create files in /tmp's filesystem
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-06-19 11:52:38 +02:00
parent 2edb0a3f3a
commit d50ea76bdc
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -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");