diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2022-05-10 13:50:04 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2022-05-10 13:58:10 +0900 |
commit | 5dc97e855bb27705a548a297b666b7be7b1c59a3 (patch) | |
tree | 87201e0c9edd25fc22e6559788ac753b7ed711de /random | |
parent | 9ba1f0091ff408d6140ee75a56fd67f02d0d3f30 (diff) | |
download | libgcrypt-5dc97e855bb27705a548a297b666b7be7b1c59a3.tar.gz |
random: Fix rndjent for Windows.
* random/jitterentropy-base-user.h [HAVE_W32_SYSTEM] (jent_ncpu):
Implement.
* random/rndjent.c (_WIN32_WINNT): Define for GetNativeSystemInfo.
(EOPNOTSUPP): Define when not available.
--
Reported-by: Eli Zaretskii
GnuPG-bug-id: 5891
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'random')
-rw-r--r-- | random/jitterentropy-base-user.h | 15 | ||||
-rw-r--r-- | random/rndjent.c | 11 |
2 files changed, 25 insertions, 1 deletions
diff --git a/random/jitterentropy-base-user.h b/random/jitterentropy-base-user.h index 389106ff..3b4274af 100644 --- a/random/jitterentropy-base-user.h +++ b/random/jitterentropy-base-user.h @@ -141,7 +141,7 @@ static inline void jent_memset_secure(void *s, size_t n) static inline long jent_ncpu(void) { -#ifdef _POSIX_SOURCE +#if defined(_POSIX_SOURCE) long ncpu = sysconf(_SC_NPROCESSORS_ONLN); if (ncpu == -1) @@ -151,6 +151,19 @@ static inline long jent_ncpu(void) return -EFAULT; return ncpu; +#elif defined(HAVE_W32_SYSTEM) + SYSTEM_INFO sysinfo; + long ncpu; + + GetNativeSystemInfo (&sysinfo); + ncpu = sysinfo.dwNumberOfProcessors; + if (ncpu <= 0) { + GetSystemInfo (&sysinfo); + ncpu = sysinfo.dwNumberOfProcessors; + } + if (ncpu <= 0) + ncpu = 1; + return ncpu; #else return 1; #endif diff --git a/random/rndjent.c b/random/rndjent.c index 14d23794..0468c7cb 100644 --- a/random/rndjent.c +++ b/random/rndjent.c @@ -45,6 +45,17 @@ #endif #include <unistd.h> #include <errno.h> +#ifndef EOPNOTSUPP +# define EOPNOTSUPP ENOSYS +#endif + +#ifdef HAVE_W32_SYSTEM +# if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0501 +# undef _WIN32_WINNT +# define _WIN32_WINNT 0x0501 /* for GetNativeSystemInfo */ +# endif +# include <windows.h> +#endif #include "types.h" #include "g10lib.h" |