* 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  <[email protected]>
 
+       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.53.0


Reply via email to