X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ftmpnam.c;h=71dc8bb1bc552578d34b1f1e0b5b3ef6248b3102;hb=c99b7daafdbf1e2415bf408e67ca7813e7ddeedf;hp=2bd72b3b7a14baaf4e1e9d9db39e4f13105895a8;hpb=0e1762539c2ad359ba10502cdfb750b5afd2329e;p=musl diff --git a/src/stdio/tmpnam.c b/src/stdio/tmpnam.c index 2bd72b3b..71dc8bb1 100644 --- a/src/stdio/tmpnam.c +++ b/src/stdio/tmpnam.c @@ -1,31 +1,27 @@ #include +#include +#include +#include +#include #include -#include -#include -#include -#include "libc.h" #include "syscall.h" -#include "atomic.h" #define MAXTRIES 100 -char *tmpnam(char *s) +char *tmpnam(char *buf) { - static int index; - static char s2[L_tmpnam]; - struct timespec ts; - int try = 0; - unsigned n; - - if (!s) s = s2; - - 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 ^ (uintptr_t)&s ^ (uintptr_t)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; + static char internal[L_tmpnam]; + char s[] = "/tmp/tmpnam_XXXXXX"; + int try; + int r; + for (try=0; try