aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2014-02-16 22:09:09 +0200
committerPetri Lehtinen <petri@digip.org>2014-02-16 22:19:37 +0200
commit946531bd7b3f6f53fecca8cdabe71218f9cf12a8 (patch)
treeadb79c55d6cade34320c9cbbc2e78129fba23d74
parent1dc87ed5a10e0268eb253f5a2f282e1cc57d63e5 (diff)
downloadjansson-946531bd7b3f6f53fecca8cdabe71218f9cf12a8.zip
jansson-946531bd7b3f6f53fecca8cdabe71218f9cf12a8.tar.gz
jansson-946531bd7b3f6f53fecca8cdabe71218f9cf12a8.tar.bz2
Merge pull request #162 from nmlgc/master
Three fixes for hashtable seeding on Windows
-rw-r--r--src/hashtable_seed.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/hashtable_seed.c b/src/hashtable_seed.c
index cb5f310..7ee8001 100644
--- a/src/hashtable_seed.c
+++ b/src/hashtable_seed.c
@@ -38,8 +38,8 @@
#endif
#if defined(_WIN32)
-/* For _getpid() */
-#include <process.h>
+/* For GetModuleHandle(), GetProcAddress() and GetCurrentProcessId() */
+#include <windows.h>
#endif
#include "jansson.h"
@@ -95,7 +95,6 @@ static int seed_from_urandom(uint32_t *seed) {
/* Windows Crypto API */
#if defined(_WIN32) && defined(USE_WINDOWS_CRYPTOAPI)
-#include <windows.h>
#include <wincrypt.h>
typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv, LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags);
@@ -112,7 +111,7 @@ static int seed_from_windows_cryptoapi(uint32_t *seed)
BYTE data[sizeof(uint32_t)];
int ok;
- hAdvAPI32 = GetModuleHandle("advapi32.dll");
+ hAdvAPI32 = GetModuleHandle(TEXT("advapi32.dll"));
if(hAdvAPI32 == NULL)
return 1;
@@ -131,7 +130,7 @@ static int seed_from_windows_cryptoapi(uint32_t *seed)
if (!pCryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
return 1;
- ok = CryptGenRandom(hCryptProv, sizeof(uint32_t), data);
+ ok = pCryptGenRandom(hCryptProv, sizeof(uint32_t), data);
pCryptReleaseContext(hCryptProv, 0);
if (!ok)
@@ -156,7 +155,7 @@ static int seed_from_timestamp_and_pid(uint32_t *seed) {
/* XOR with PID for more randomness */
#if defined(_WIN32)
- *seed ^= (uint32_t)_getpid();
+ *seed ^= (uint32_t)GetCurrentProcessId();
#elif defined(HAVE_GETPID)
*seed ^= (uint32_t)getpid();
#endif