summaryrefslogtreecommitdiff
path: root/05/stdio.h
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-02-16 22:58:16 -0500
committerpommicket <pommicket@gmail.com>2022-02-16 22:58:16 -0500
commit6e1158f49aa014b801b171b358c47389e7f9964e (patch)
tree5702e0b1ce33dd58a42a0cdfa8d90267a82a6fb3 /05/stdio.h
parentb1e837afb44f9053763d6a654a5f7bb2757a39d4 (diff)
the last parts of the C standard library
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