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