12 char *tempnam(const char *dir, const char *pfx)
22 if (!dir) dir = P_tmpdir;
23 if (!pfx) pfx = "temp";
25 if (access(dir, R_OK|W_OK|X_OK) != 0)
28 l = strlen(dir) + 1 + strlen(pfx) + 3*(sizeof(int)*3+2) + 1;
33 clock_gettime(CLOCK_REALTIME, &ts);
34 n = ts.tv_nsec ^ (uintptr_t)&s ^ (uintptr_t)s;
35 snprintf(s, l, "%s/%s-%d-%d-%x", dir, pfx, pid, a_fetch_add(&index, 1), n);
36 } while (!access(s, F_OK) && try++<MAXTRIES);