185025f13ee3c7872b2fa85c52e400d82b4021a6
[musl] / src / stdio / tmpfile.c
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 #include "stdio_impl.h"
5
6 FILE *tmpfile(void)
7 {
8         char buf[L_tmpnam], *s;
9         int fd;
10         FILE *f;
11         for (;;) {
12                 s = tmpnam(buf);
13                 if (!s) return NULL;
14                 fd = __syscall_open(s, O_RDWR | O_CREAT | O_EXCL, 0600);
15                 if (fd >= 0) {
16                         f = __fdopen(fd, "w+");
17                         remove(s);
18                         return f;
19                 }
20         }
21 }
22
23 LFS64(tmpfile);