diff options
author | Guy Harris <gharris@sonic.net> | 2023-07-17 19:33:12 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2023-07-17 19:33:12 -0700 |
commit | eac19ab00709ee62989364368ed86e474e2f4445 (patch) | |
tree | fd83145207387996f09147b1c0af0f7fa54ef634 | |
parent | 889d0d6e6c03f8b11abfa432b897e83533afec8c (diff) |
Simplify the "is this NT workstation" test.
Pull it into a common routine, and get rid of the old workaround for
MSVC 6 - we had other code that required VER_NT_WORKSTATION to be
defined and required an OSVERSIONINFOEX to have a wProductType member
(not to mention required that there be an OSVERSIONINFOEX structure in
the first place), and it's been compiling just fine.
-rw-r--r-- | wsutil/os_version_info.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/wsutil/os_version_info.c b/wsutil/os_version_info.c index 061df0086f..79d16a39b3 100644 --- a/wsutil/os_version_info.c +++ b/wsutil/os_version_info.c @@ -183,6 +183,15 @@ typedef LONG (WINAPI * RtlGetVersionProc) (OSVERSIONINFOEX *); #define STATUS_SUCCESS 0 #endif #include <stdlib.h> + +/* + * Test whether the OS an "NT Workstation" version, meaning "not server". + */ +static gboolean +is_nt_workstation(OSVERSIONINFOEX *win_version_info) +{ + return win_version_info->wProductType == VER_NT_WORKSTATION; +} #endif // _WIN32 /* @@ -347,7 +356,7 @@ DIAG_ON(cast-function-type) break; case 2: - if ((win_version_info.wProductType == VER_NT_WORKSTATION) && + if (is_nt_workstation(&win_version_info) && (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) { g_string_append_printf(str, "Windows XP Professional x64 Edition"); } else { @@ -368,30 +377,22 @@ DIAG_ON(cast-function-type) /* * Vista, W7, W8, W8.1, and their server versions. */ - gboolean is_nt_workstation; - if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) g_string_append(str, "64-bit "); else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) g_string_append(str, "32-bit "); -#ifndef VER_NT_WORKSTATION -#define VER_NT_WORKSTATION 0x01 - is_nt_workstation = ((win_version_info.wReserved[1] & 0xff) == VER_NT_WORKSTATION); -#else - is_nt_workstation = (win_version_info.wProductType == VER_NT_WORKSTATION); -#endif switch (win_version_info.dwMinorVersion) { case 0: - g_string_append_printf(str, is_nt_workstation ? "Windows Vista" : "Windows Server 2008"); + g_string_append_printf(str, is_nt_workstation(&win_version_info) ? "Windows Vista" : "Windows Server 2008"); break; case 1: - g_string_append_printf(str, is_nt_workstation ? "Windows 7" : "Windows Server 2008 R2"); + g_string_append_printf(str, is_nt_workstation(&win_version_info) ? "Windows 7" : "Windows Server 2008 R2"); break; case 2: - g_string_append_printf(str, is_nt_workstation ? "Windows 8" : "Windows Server 2012"); + g_string_append_printf(str, is_nt_workstation(&win_version_info) ? "Windows 8" : "Windows Server 2012"); break; case 3: - g_string_append_printf(str, is_nt_workstation ? "Windows 8.1" : "Windows Server 2012 R2"); + g_string_append_printf(str, is_nt_workstation(&win_version_info) ? "Windows 8.1" : "Windows Server 2012 R2"); break; default: g_string_append_printf(str, "Windows NT, unknown version %lu.%lu", @@ -405,7 +406,6 @@ DIAG_ON(cast-function-type) /* * W10, W11, and their server versions. */ - gboolean is_nt_workstation; TCHAR ReleaseId[10]; DWORD ridSize = _countof(ReleaseId); @@ -413,12 +413,11 @@ DIAG_ON(cast-function-type) g_string_append(str, "64-bit "); else if (system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) g_string_append(str, "32-bit "); - is_nt_workstation = (win_version_info.wProductType == VER_NT_WORKSTATION); switch (win_version_info.dwMinorVersion) { case 0: /* List of BuildNumber from https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions * and https://docs.microsoft.com/en-us/windows/release-health/windows11-release-information */ - if (is_nt_workstation) { + if (is_nt_workstation(&win_version_info)) { if (win_version_info.dwBuildNumber < 10240) { /* XXX - W10 builds before 10240? */ g_string_append_printf(str, "Windows"); |