From 2fbaa37725d14ebeae463fbe7e2ed912327f85a5 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 3 Oct 2009 20:34:12 +0200 Subject: [PATCH] Do only one call to GetVersionEx in the common case. --- ChangeLog | 6 ++++++ lib/uname.c | 28 ++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d8cf65ff..5c9efe447 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ 2009-10-03 Paolo Bonzini Bruno Haible + * lib/uname.c: Include . + (uname): Do only one call to GetVersionEx in the common case. + +2009-10-03 Paolo Bonzini + Bruno Haible + * lib/uname.c (VER_PLATFORM_WIN32_CE, PROCESSOR_ARCHITECTURE_AMD64, PROCESSOR_ARCHITECTURE_IA32_ON_WIN64): Define fallbacks. (uname): Add support for Windows CE and various non-x86 CPU types. diff --git a/lib/uname.c b/lib/uname.c index 70ebb95e5..95c577698 100644 --- a/lib/uname.c +++ b/lib/uname.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -49,16 +50,31 @@ int uname (struct utsname *buf) { OSVERSIONINFO version; + OSVERSIONINFOEX versionex; + BOOL have_versionex; /* indicates whether versionex is filled */ const char *super_version; + /* Preparation: Fill version and, if possible, also versionex. + But try to call GetVersionEx only once in the common case. */ + versionex.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX); + have_versionex = GetVersionEx (&versionex); + if (have_versionex) + { + /* We know that OSVERSIONINFO is a subset of OSVERSIONINFOEX. */ + memcpy (&version, &versionex, sizeof (OSVERSIONINFO)); + } + else + { + version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + if (!GetVersionEx (&version)) + abort (); + } + /* Fill in nodename. */ if (gethostname (buf->nodename, sizeof (buf->nodename)) < 0) strcpy (buf->nodename, "localhost"); /* Determine major-major Windows version. */ - version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); - if (!GetVersionEx (&version)) - abort (); if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) { /* Windows NT or newer. */ @@ -135,11 +151,7 @@ uname (struct utsname *buf) } else if (version.dwMajorVersion == 6) { - OSVERSIONINFOEX versionex; - - versionex.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX); - if (GetVersionEx ((OSVERSIONINFO *) &versionex) - && versionex.wProductType != VER_NT_WORKSTATION) + if (have_versionex && versionex.wProductType != VER_NT_WORKSTATION) strcpy (buf->release, "Windows Server 2008"); else switch (version.dwMinorVersion) -- 2.11.0