bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/3 v2] uname: use only one OSVERSIONINFOEX struct


From: Paolo Bonzini
Subject: [PATCH 1/3 v2] uname: use only one OSVERSIONINFOEX struct
Date: Fri, 2 Oct 2009 03:00:07 +0200

* lib/uname.c: Use GetVersionEx, move API calls to the beginning,
try to get OSVERSIONINFOEX first and fall back to OSVERSIONINFO.
---
        Same as 2/5 + 3/5 from the previous series, without assert,
        without A suffix, without reindentation (left for next patch).

 ChangeLog   |    5 ++
 lib/uname.c |   23 ++++++++++++++---------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/lib/uname.c b/lib/uname.c
index 1eec7e2..18c611c 100644
--- a/lib/uname.c
+++ b/lib/uname.c
@@ -34,7 +34,7 @@
 int
 uname (struct utsname *buf)
 {
-  OSVERSIONINFO version;
+  OSVERSIONINFOEX version;
   BOOL have_version;
   const char *super_version;
 
@@ -42,9 +42,18 @@ uname (struct utsname *buf)
   if (gethostname (buf->nodename, sizeof (buf->nodename)) < 0)
     strcpy (buf->nodename, "localhost");
 
-  /* Determine major-major Windows version.  */
-  version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
-  have_version = GetVersionEx (&version);
+  /* Determine major-minor Windows version.  */
+  version.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
+  have_version = GetVersionEx ((OSVERSIONINFO *) &version);
+  if (!have_version)
+    {
+      /* OSVERSIONINFOEX info not available, live with OSVERSIONINFO which
+        is a subset.  */
+      memset (&version, 0, sizeof (version));
+      version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
+      have_version = GetVersionEx ((OSVERSIONINFO *) &version);
+    }
+
   if (have_version)
     {
       if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
@@ -129,11 +138,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 (version.wProductType != VER_NT_WORKSTATION)
                strcpy (buf->release, "Windows Server 2008");
              else
                switch (version.dwMinorVersion)
-- 
1.6.2.5






reply via email to

[Prev in Thread] Current Thread [Next in Thread]