From 4abab5ad6c8465a7528ccdd5f49367da05f78bbd Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Tue, 1 Oct 2024 15:47:05 +0200 Subject: Initial version --- src/stdio/tmpfile.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/stdio/tmpfile.c (limited to 'src/stdio/tmpfile.c') diff --git a/src/stdio/tmpfile.c b/src/stdio/tmpfile.c new file mode 100644 index 0000000..2fa8803 --- /dev/null +++ b/src/stdio/tmpfile.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include "stdio_impl.h" + +#define MAXTRIES 100 + +FILE *tmpfile(void) +{ + char s[] = "/tmp/tmpfile_XXXXXX"; + int fd; + FILE *f; + int try; + for (try=0; try= 0) { +#ifdef SYS_unlink + __syscall(SYS_unlink, s); +#else + __syscall(SYS_unlinkat, AT_FDCWD, s, 0); +#endif + f = __fdopen(fd, "w+"); + if (!f) __syscall(SYS_close, fd); + return f; + } + } + return 0; +} -- cgit v1.2.3