X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ftmpnam.c;h=449eb9b0708c2a5d295db76f1e944059f6789f9b;hb=51fc77c7c03fa0b300e9a609b18f11f0e4db065a;hp=010cf039aac07ee84759c5f5b6950821b787fbec;hpb=8250742b90b8b54e642fa9201bf0cf8b7c27bbb8;p=musl diff --git a/src/stdio/tmpnam.c b/src/stdio/tmpnam.c index 010cf039..449eb9b0 100644 --- a/src/stdio/tmpnam.c +++ b/src/stdio/tmpnam.c @@ -1,30 +1,29 @@ #include -#include -#include -#include -#include "libc.h" +#include +#include +#include +#include #include "syscall.h" -#include "atomic.h" #define MAXTRIES 100 -char *tmpnam(char *s) -{ - static int index; - static char s2[L_tmpnam]; - struct timespec ts; - int try = 0; - unsigned n; - - if (!s) s = s2; +char *__randname(char *); - if (__syscall(SYS_access, P_tmpdir, R_OK|W_OK|X_OK) != 0) - return NULL; - - do { - __syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts, 0); - n = ts.tv_nsec ^ (unsigned)&s ^ (unsigned)s; - snprintf(s, L_tmpnam, "/tmp/t%x-%x", a_fetch_add(&index, 1), n); - } while (!__syscall(SYS_access, s, F_OK) && try++=MAXTRIES ? 0 : s; +char *tmpnam(char *buf) +{ + static char internal[L_tmpnam]; + char s[] = "/tmp/tmpnam_XXXXXX"; + int try; + int r; + for (try=0; try