summaryrefslogtreecommitdiff
path: root/05/stdio.h
diff options
context:
space:
mode:
Diffstat (limited to '05/stdio.h')
-rw-r--r--05/stdio.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/05/stdio.h b/05/stdio.h
index e5a04cc..e474fca 100644
--- a/05/stdio.h
+++ b/05/stdio.h
@@ -1739,7 +1739,9 @@ int rename(const char *old, const char *new) {
char *tmpnam(char *s) {
struct timespec t = {0};
- do {
+ do {
+ // NB: we can't use rand() here because
+ // "The implementation shall behave as if no library function calls the rand function." C89 ยง 4.10.2.1
clock_gettime(CLOCK_MONOTONIC, &t); // use clock as a source of randomness
sprintf(s, "/tmp/C_%06u", t.tv_nsec % 1000000);
} while (access(s, F_OK) == 0); // if file exists, generate a new name