1
0
mirror of https://https.git.savannah.gnu.org/git/gnulib.git synced 2026-04-28 06:33:36 +00:00

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.
This commit is contained in:
Paul Eggert
2026-04-11 14:06:09 -07:00
parent 9bd5952ee9
commit ed31e3616a
2 changed files with 13 additions and 1 deletions

View File

@@ -1,5 +1,15 @@
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

View 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);
#else
v = mix_random_values (v, clock ());
#endif
*r = mix_random_values (v, clock ());
*r = v;
return false;
}