From ed31e3616abfc6d21dcb851aa025756878eec60b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 11 Apr 2026 14:06:09 -0700 Subject: [PATCH] =?utf8?q?tempname:=20call=20=E2=80=98clock=E2=80=99=20onl?= =?utf8?q?y=20if=20!CLOCK=5FREALTIME?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * lib/tempname.c (random_bits) [CLOCK_REALTIME]: Do not call ‘clock’, as an optimization. There is no need to call ‘clock’, as it likely gives us less info than clock_gettime, and if clock_gettime fails then ‘clock’ will likely fail too. This patch is a simplified version of the patch made in glibc commit 5f62cf88c4530c11904482775b7582bd7f6d80d2 dated 2024-09-25, and Gnulib lib/tempname.c should now be suitable as-is for replacing Glibc sysdeps/posix/tempname.c. --- ChangeLog | 10 ++++++++++ lib/tempname.c | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3db1faa024..eaaef305f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2026-04-11 Paul Eggert + tempname: call ‘clock’ only if !CLOCK_REALTIME + * lib/tempname.c (random_bits) [CLOCK_REALTIME]: Do not call + ‘clock’, as an optimization. There is no need to call ‘clock’, as + it likely gives us less info than clock_gettime, and if + clock_gettime fails then ‘clock’ will likely fail too. + This patch is a simplified version of the patch made in glibc commit + 5f62cf88c4530c11904482775b7582bd7f6d80d2 dated 2024-09-25, + and Gnulib lib/tempname.c should now be suitable as-is for + replacing Glibc sysdeps/posix/tempname.c. + doc: be more like POSIX in threading terms In documentation and comments, be more like POSIX in terminology involving multithreading. Explain the distinction between diff --git a/lib/tempname.c b/lib/tempname.c index 1edba07a02..6b166253e8 100644 --- a/lib/tempname.c +++ b/lib/tempname.c @@ -111,9 +111,11 @@ random_bits (random_value *r, random_value s) __clock_gettime64 (CLOCK_REALTIME, &tv); v = mix_random_values (v, tv.tv_sec); v = mix_random_values (v, tv.tv_nsec); +#else + v = mix_random_values (v, clock ()); #endif - *r = mix_random_values (v, clock ()); + *r = v; return false; } -- 2.47.3