libc: Make tmpfile() create files in /tmp's filesystem
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2edb0a3f3a
commit
d50ea76bdc
@ -11,6 +11,13 @@ FILE* stdin = nullptr;
|
|||||||
FILE* stderr = nullptr;
|
FILE* stderr = nullptr;
|
||||||
FILE* stdout = 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)
|
static int fopen_parse_mode(const char* mode)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@ -477,8 +484,7 @@ extern "C"
|
|||||||
|
|
||||||
FILE* tmpfile()
|
FILE* tmpfile()
|
||||||
{
|
{
|
||||||
// FIXME: use /tmp as the directory when the tmpfs is mounted only there.
|
int fd = open(read_tmpdir(), O_RDWR | O_TMPFILE, 0600);
|
||||||
int fd = open("/", O_RDWR | O_TMPFILE, 0600);
|
|
||||||
if (fd < 0) return nullptr;
|
if (fd < 0) return nullptr;
|
||||||
|
|
||||||
FILE* f = fdopen(fd, "w+b");
|
FILE* f = fdopen(fd, "w+b");
|
||||||
|
Loading…
Reference in New Issue
Block a user