]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
tempname: call ‘clock’ only if !CLOCK_REALTIME master
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 11 Apr 2026 21:06:09 +0000 (14:06 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 11 Apr 2026 21:07:00 +0000 (14:07 -0700)
* 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
lib/tempname.c

index 3db1faa0245cf6d220d864818c7a1b42e1eb871f..eaaef305f620c875b288aded6bb835cc6698bc13 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2026-04-11  Paul Eggert  <eggert@cs.ucla.edu>
 
 2026-04-11  Paul Eggert  <eggert@cs.ucla.edu>
 
+       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
        doc: be more like POSIX in threading terms
        In documentation and comments, be more like POSIX in terminology
        involving multithreading.  Explain the distinction between
index 1edba07a02ca32d7eb60d9c21690dd6787a5ce49..6b166253e82a6a8c3779d64b4076d3e5babd5fc7 100644 (file)
@@ -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);
   __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
 
 #endif
 
-  *r = mix_random_values (v, clock ());
+  *r = v;
   return false;
 }
 
   return false;
 }