From 466cbfe6fd944a343caf29662f3b175a2ebdb7dc Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 8 Aug 2021 11:13:04 +0100 Subject: win32: code shrink Save a few bytes: - When collecting entropy prefer functions we call elsewhere. - In uname(2) set 32-bit processor type to i686 and tweak it for i386. --- win32/isaac.c | 6 +++--- win32/sh_random.c | 6 +++--- win32/uname.c | 11 +++++------ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/win32/isaac.c b/win32/isaac.c index 2b02eaff2..f419a3f2e 100644 --- a/win32/isaac.c +++ b/win32/isaac.c @@ -129,7 +129,7 @@ static void randinit(isaac_t *t, int flag) static void get_entropy(isaac_t *t) { int i, j, len; - SYSTEMTIME tm; + FILETIME tm; MEMORYSTATUS ms; SYSTEM_INFO si; LARGE_INTEGER pc; @@ -139,11 +139,11 @@ static void get_entropy(isaac_t *t) unsigned char buf[16]; i = 0; - t->randrsl[i++] = (uint32_t)GetCurrentProcessId(); + t->randrsl[i++] = (uint32_t)GetProcessId(GetCurrentProcess()); t->randrsl[i++] = (uint32_t)GetCurrentThreadId(); t->randrsl[i++] = (uint32_t)GetTickCount(); - GET_DATA(GetLocalTime, tm) + GET_DATA(GetSystemTimeAsFileTime, tm) GET_DATA(GlobalMemoryStatus, ms) GET_DATA(GetSystemInfo, si) GET_DATA(QueryPerformanceCounter, pc) diff --git a/win32/sh_random.c b/win32/sh_random.c index 2948e4a55..912793269 100644 --- a/win32/sh_random.c +++ b/win32/sh_random.c @@ -17,18 +17,18 @@ static void get_entropy(uint32_t state[2]) { int i, j; - SYSTEMTIME tm; + FILETIME tm; MEMORYSTATUS ms; SYSTEM_INFO si; LARGE_INTEGER pc; uint32_t *u; i = 0; - state[i++%2] ^= (uint32_t)GetCurrentProcessId(); + state[i++%2] ^= (uint32_t)GetProcessId(GetCurrentProcess()); state[i++%2] ^= (uint32_t)GetCurrentThreadId(); state[i++%2] ^= (uint32_t)GetTickCount(); - GET_DATA(GetLocalTime, tm) + GET_DATA(GetSystemTimeAsFileTime, tm) GET_DATA(GlobalMemoryStatus, ms) GET_DATA(GetSystemInfo, si) GET_DATA(QueryPerformanceCounter, pc) diff --git a/win32/uname.c b/win32/uname.c index 516aa5ea2..008d67a8b 100644 --- a/win32/uname.c +++ b/win32/uname.c @@ -17,12 +17,13 @@ int uname(struct utsname *name) memset(&os_info, 0, sizeof(OSVERSIONINFO)); os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - strcpy(name->release, unk); - strcpy(name->version, unk); if (GetVersionEx(&os_info)) { sprintf(name->release, "%u.%u", (unsigned int)os_info.dwMajorVersion, (unsigned int)os_info.dwMinorVersion); sprintf(name->version, "%u", (unsigned int)os_info.dwBuildNumber); + } else { + strcpy(name->release, unk); + strcpy(name->version, unk); } GetSystemInfo(&sys_info); @@ -31,11 +32,9 @@ int uname(struct utsname *name) strcpy(name->machine, "x86_64"); break; case PROCESSOR_ARCHITECTURE_INTEL: + strcpy(name->machine, "i686"); if (sys_info.wProcessorLevel < 6) { - strcpy(name->machine, "i386"); - } - else { - strcpy(name->machine, "i686"); + name->machine[1] = '3'; } break; default: -- cgit v1.2.3-55-g6feb