2011-02-12 00:22:29 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "stdio_impl.h"
|
|
|
|
|
2011-03-29 08:37:57 -04:00
|
|
|
#define MAXTRIES 100
|
|
|
|
|
2011-02-12 00:22:29 -05:00
|
|
|
FILE *tmpfile(void)
|
|
|
|
{
|
|
|
|
char buf[L_tmpnam], *s;
|
|
|
|
int fd;
|
|
|
|
FILE *f;
|
2011-03-29 08:37:57 -04:00
|
|
|
int try;
|
|
|
|
for (try=0; try<MAXTRIES; try++) {
|
2011-02-12 00:22:29 -05:00
|
|
|
s = tmpnam(buf);
|
2011-03-29 08:37:57 -04:00
|
|
|
if (!s) return 0;
|
2011-03-20 00:16:43 -04:00
|
|
|
fd = syscall(SYS_open, s, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600);
|
2011-02-12 00:22:29 -05:00
|
|
|
if (fd >= 0) {
|
|
|
|
f = __fdopen(fd, "w+");
|
2011-04-17 16:32:15 -04:00
|
|
|
__syscall(SYS_unlink, s);
|
2011-02-12 00:22:29 -05:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
2011-03-29 08:37:57 -04:00
|
|
|
return 0;
|
2011-02-12 00:22:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
LFS64(tmpfile);
|