# HG changeset patch # User Bruno Haible # Date 1254594852 -7200 # Node ID 5c028172c2a2391380d120ce772d807370576a4e # Parent a141d503d085c5e65475642aa168b39a2de0dd5c Do only one call to GetVersionEx in the common case. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +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 diff --git a/lib/uname.c b/lib/uname.c --- a/lib/uname.c +++ b/lib/uname.c @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -49,16 +50,31 @@ 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 @@ } 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)