- LOCK(&lock);
- for (index++; index < TMP_MAX; index++) {
- snprintf(s, L_tmpnam, "%s/temp%d-%d", dir, pid, index);
- if (access(s, F_OK) != 0) {
- UNLOCK(&lock);
- return s;
- }
- }
- UNLOCK(&lock);
- 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);
+ return try>=MAXTRIES ? 0 : s;