diff options
| author | Ron Yorston <rmy@pobox.com> | 2021-08-08 11:13:04 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2021-08-08 11:13:04 +0100 |
| commit | 466cbfe6fd944a343caf29662f3b175a2ebdb7dc (patch) | |
| tree | c109f9d86e42c12f9a1613e1fec8aa2f8018524a | |
| parent | c6bb78bf30f17aeac45e4bf9ea7eb1856fb5cdb7 (diff) | |
| download | busybox-w32-466cbfe6fd944a343caf29662f3b175a2ebdb7dc.tar.gz busybox-w32-466cbfe6fd944a343caf29662f3b175a2ebdb7dc.tar.bz2 busybox-w32-466cbfe6fd944a343caf29662f3b175a2ebdb7dc.zip | |
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.
| -rw-r--r-- | win32/isaac.c | 6 | ||||
| -rw-r--r-- | win32/sh_random.c | 6 | ||||
| -rw-r--r-- | 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) | |||
| 129 | static void get_entropy(isaac_t *t) | 129 | static void get_entropy(isaac_t *t) |
| 130 | { | 130 | { |
| 131 | int i, j, len; | 131 | int i, j, len; |
| 132 | SYSTEMTIME tm; | 132 | FILETIME tm; |
| 133 | MEMORYSTATUS ms; | 133 | MEMORYSTATUS ms; |
| 134 | SYSTEM_INFO si; | 134 | SYSTEM_INFO si; |
| 135 | LARGE_INTEGER pc; | 135 | LARGE_INTEGER pc; |
| @@ -139,11 +139,11 @@ static void get_entropy(isaac_t *t) | |||
| 139 | unsigned char buf[16]; | 139 | unsigned char buf[16]; |
| 140 | 140 | ||
| 141 | i = 0; | 141 | i = 0; |
| 142 | t->randrsl[i++] = (uint32_t)GetCurrentProcessId(); | 142 | t->randrsl[i++] = (uint32_t)GetProcessId(GetCurrentProcess()); |
| 143 | t->randrsl[i++] = (uint32_t)GetCurrentThreadId(); | 143 | t->randrsl[i++] = (uint32_t)GetCurrentThreadId(); |
| 144 | t->randrsl[i++] = (uint32_t)GetTickCount(); | 144 | t->randrsl[i++] = (uint32_t)GetTickCount(); |
| 145 | 145 | ||
| 146 | GET_DATA(GetLocalTime, tm) | 146 | GET_DATA(GetSystemTimeAsFileTime, tm) |
| 147 | GET_DATA(GlobalMemoryStatus, ms) | 147 | GET_DATA(GlobalMemoryStatus, ms) |
| 148 | GET_DATA(GetSystemInfo, si) | 148 | GET_DATA(GetSystemInfo, si) |
| 149 | GET_DATA(QueryPerformanceCounter, pc) | 149 | 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 @@ | |||
| 17 | static void get_entropy(uint32_t state[2]) | 17 | static void get_entropy(uint32_t state[2]) |
| 18 | { | 18 | { |
| 19 | int i, j; | 19 | int i, j; |
| 20 | SYSTEMTIME tm; | 20 | FILETIME tm; |
| 21 | MEMORYSTATUS ms; | 21 | MEMORYSTATUS ms; |
| 22 | SYSTEM_INFO si; | 22 | SYSTEM_INFO si; |
| 23 | LARGE_INTEGER pc; | 23 | LARGE_INTEGER pc; |
| 24 | uint32_t *u; | 24 | uint32_t *u; |
| 25 | 25 | ||
| 26 | i = 0; | 26 | i = 0; |
| 27 | state[i++%2] ^= (uint32_t)GetCurrentProcessId(); | 27 | state[i++%2] ^= (uint32_t)GetProcessId(GetCurrentProcess()); |
| 28 | state[i++%2] ^= (uint32_t)GetCurrentThreadId(); | 28 | state[i++%2] ^= (uint32_t)GetCurrentThreadId(); |
| 29 | state[i++%2] ^= (uint32_t)GetTickCount(); | 29 | state[i++%2] ^= (uint32_t)GetTickCount(); |
| 30 | 30 | ||
| 31 | GET_DATA(GetLocalTime, tm) | 31 | GET_DATA(GetSystemTimeAsFileTime, tm) |
| 32 | GET_DATA(GlobalMemoryStatus, ms) | 32 | GET_DATA(GlobalMemoryStatus, ms) |
| 33 | GET_DATA(GetSystemInfo, si) | 33 | GET_DATA(GetSystemInfo, si) |
| 34 | GET_DATA(QueryPerformanceCounter, pc) | 34 | 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) | |||
| 17 | memset(&os_info, 0, sizeof(OSVERSIONINFO)); | 17 | memset(&os_info, 0, sizeof(OSVERSIONINFO)); |
| 18 | os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | 18 | os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
| 19 | 19 | ||
| 20 | strcpy(name->release, unk); | ||
| 21 | strcpy(name->version, unk); | ||
| 22 | if (GetVersionEx(&os_info)) { | 20 | if (GetVersionEx(&os_info)) { |
| 23 | sprintf(name->release, "%u.%u", (unsigned int)os_info.dwMajorVersion, | 21 | sprintf(name->release, "%u.%u", (unsigned int)os_info.dwMajorVersion, |
| 24 | (unsigned int)os_info.dwMinorVersion); | 22 | (unsigned int)os_info.dwMinorVersion); |
| 25 | sprintf(name->version, "%u", (unsigned int)os_info.dwBuildNumber); | 23 | sprintf(name->version, "%u", (unsigned int)os_info.dwBuildNumber); |
| 24 | } else { | ||
| 25 | strcpy(name->release, unk); | ||
| 26 | strcpy(name->version, unk); | ||
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | GetSystemInfo(&sys_info); | 29 | GetSystemInfo(&sys_info); |
| @@ -31,11 +32,9 @@ int uname(struct utsname *name) | |||
| 31 | strcpy(name->machine, "x86_64"); | 32 | strcpy(name->machine, "x86_64"); |
| 32 | break; | 33 | break; |
| 33 | case PROCESSOR_ARCHITECTURE_INTEL: | 34 | case PROCESSOR_ARCHITECTURE_INTEL: |
| 35 | strcpy(name->machine, "i686"); | ||
| 34 | if (sys_info.wProcessorLevel < 6) { | 36 | if (sys_info.wProcessorLevel < 6) { |
| 35 | strcpy(name->machine, "i386"); | 37 | name->machine[1] = '3'; |
| 36 | } | ||
| 37 | else { | ||
| 38 | strcpy(name->machine, "i686"); | ||
| 39 | } | 38 | } |
| 40 | break; | 39 | break; |
| 41 | default: | 40 | default: |
