riscv32: add dlsym
[musl.git] / src / stdio / tmpfile.c
blob2fa8803fc2312c64465d83819f4e15f452909a75
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <stdlib.h>
4 #include "stdio_impl.h"
6 #define MAXTRIES 100
8 FILE *tmpfile(void)
10 char s[] = "/tmp/tmpfile_XXXXXX";
11 int fd;
12 FILE *f;
13 int try;
14 for (try=0; try<MAXTRIES; try++) {
15 __randname(s+13);
16 fd = sys_open(s, O_RDWR|O_CREAT|O_EXCL, 0600);
17 if (fd >= 0) {
18 #ifdef SYS_unlink
19 __syscall(SYS_unlink, s);
20 #else
21 __syscall(SYS_unlinkat, AT_FDCWD, s, 0);
22 #endif
23 f = __fdopen(fd, "w+");
24 if (!f) __syscall(SYS_close, fd);
25 return f;
28 return 0;