bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 2/5] uname: use only one OSVERSIONINFOEXA struct, use ANSI versio


From: Paolo Bonzini
Subject: [PATCH 2/5] uname: use only one OSVERSIONINFOEXA struct, use ANSI version
Date: Thu, 1 Oct 2009 14:15:08 +0200

This first uname cleanup switches to ANSI functions, and moves all
GetVersionEx (now GetVersionExA) calls to the beginning of the function.
This way, the calls can share one struct (OSVERSIONINFOEXA begins with
the same fields that are in OSVERSIONINFOA).

It temporarily asserts that Windows NT can provide OSVERSIONINFOEX
information.  This is just to simplify the patch, I will remove the
limitation in the next one.

* lib/uname.c: Use GetVersionExA, move API calls to the beginning.
---
 ChangeLog   |    5 +++++
 lib/uname.c |   20 +++++++++++---------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 328a808..1ab1255 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-10-01  Paolo Bonzini  <address@hidden>
 
+       Use only one OSVERSIONINFOEXA struct, use ANSI version.
+       * lib/uname.c: Use GetVersionExA, move API calls to the beginning.
+
+2009-10-01  Paolo Bonzini  <address@hidden>
+
        Use ANSI Win32 functions.
        * lib/getaddrinfo.c: Use ANSI functions.
        * lib/link.c: Use GetModuleHandleA.
diff --git a/lib/uname.c b/lib/uname.c
index 1eec7e2..d92e972 100644
--- a/lib/uname.c
+++ b/lib/uname.c
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <windows.h>
+#include <assert.h>
 
 /* Mingw headers don't have latest processor codes.  */
 #ifndef PROCESSOR_AMD_X8664
@@ -34,7 +35,7 @@
 int
 uname (struct utsname *buf)
 {
-  OSVERSIONINFO version;
+  OSVERSIONINFOEXA version;
   BOOL have_version;
   const char *super_version;
 
@@ -42,15 +43,20 @@ 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-major Windows version.  OSVERSIONINFOEXA starts 
+     with the same fields as OSVERSIONINFOA, request those first.  */
+  version.dwOSVersionInfoSize = sizeof (OSVERSIONINFOA);
+  have_version = GetVersionExA ((OSVERSIONINFOA *) &version);
   if (have_version)
     {
       if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
        {
          /* Windows NT or newer.  */
          super_version = "NT";
+
+         version.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEXA);
+         have_version = GetVersionExA ((OSVERSIONINFOA *) &version);
+         assert (have_version);
        }
       else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
        {
@@ -129,11 +135,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]