X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ftmpnam.c;h=6c7c253a6d6ef94bed9e4a10c08ceb7b39b1901c;hb=54316a52b2119edf73e274c8b4f25d7757f7b4d3;hp=6099b74b4c80f261c14201d6c0f62eea010674c3;hpb=507a9fa6ff9948eb7d858467b7be2cb1dcf15d03;p=musl diff --git a/src/stdio/tmpnam.c b/src/stdio/tmpnam.c index 6099b74b..6c7c253a 100644 --- a/src/stdio/tmpnam.c +++ b/src/stdio/tmpnam.c @@ -1,30 +1,28 @@ #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 ^ (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++