bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH 4/5] Handle Windows CE and rewrite NT version handling.


From: Paolo Bonzini
Subject: [PATCH 4/5] Handle Windows CE and rewrite NT version handling.
Date: Thu, 1 Oct 2009 14:15:10 +0200

This further patch improves detection of Windows CE and of the processor
kinds (ARM, SH, etc.) supported by Windows CE as well as older versions
of Windows.  I also made it return i686 for WoW64 (Win32-on-Win64).

At the same time, Windows 95/98/ME never supported anything but 32-bit
x86, so its section can be simplified.

* lib/uname.c: Handle Windows CE and its processor types.  Remove
code for processors never supported by Windows 95/98/ME.  Rewrite
conversion of NT version numbers to product names.
---
 ChangeLog   |    7 +++
 lib/uname.c |  140 ++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 84 insertions(+), 63 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e0819f3..50d746d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-10-01  Paolo Bonzini  <address@hidden>
 
+       Handle Windows CE and rewrite NT version handling.
+       * lib/uname.c: Handle Windows CE and its processor types.  Remove
+       code for processors never supported by Windows 95/98/ME.  Rewrite
+       conversion of NT version numbers to product names.
+
+2009-10-01  Paolo Bonzini  <address@hidden>
+
        Assume GetVersionEx info is available, try to use only one call.
        * lib/uname.c: Check for OSVERSIONINFOEXA and fall back to
        OSVERSIONINFOA.  After that, assume version info is available
diff --git a/lib/uname.c b/lib/uname.c
index 52519a6..a63d150 100644
--- a/lib/uname.c
+++ b/lib/uname.c
@@ -28,16 +28,19 @@
 #include <windows.h>
 #include <assert.h>
 
-/* Mingw headers don't have latest processor codes.  */
-#ifndef PROCESSOR_AMD_X8664
-# define PROCESSOR_AMD_X8664 8664
+/* Some headers lack some codes.  */
+#ifndef VER_PLATFORM_WIN32_WINDOWS
+# define VER_PLATFORM_WIN32_WINDOWS 1
+#endif
+#ifndef VER_PLATFORM_WIN32_CE
+# define VER_PLATFORM_WIN32_CE 3
 #endif
 
 int
 uname (struct utsname *buf)
 {
   OSVERSIONINFOEXA version;
-  BOOL have_version;
+  BOOL have_version, is_server;
   const char *super_version;
 
   /* Fill in nodename.  */
@@ -61,6 +64,11 @@ uname (struct utsname *buf)
       /* Windows NT or newer.  */
       super_version = "NT";
     }
+  else if (version.dwPlatformId == VER_PLATFORM_WIN32_CE)
+    {
+      /* Windows CE.  */
+      super_version = "CE";
+    }
   else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
     {
       /* Windows 95/98/ME.  */
@@ -102,52 +110,51 @@ uname (struct utsname *buf)
        $ ./uname.exe -r      => 1.0.11(0.46/3/2)
        $ ./uname.exe -v      => 2008-08-25 23:40
      There is no point in imitating this behaviour.  */
-  if (version.dwPlatformId == VER_PLATFORM_WIN32_NT)
+  switch (version.dwPlatformId)
     {
-      /* Windows NT or newer.  */
-      if (version.dwMajorVersion <= 4)
-       sprintf (buf->release, "Windows NT %u.%u",
-                (unsigned int) version.dwMajorVersion,
-                (unsigned int) version.dwMinorVersion);
-      else if (version.dwMajorVersion == 5)
-       switch (version.dwMinorVersion)
-         {
-         case 0:
-           strcpy (buf->release, "Windows 2000");
-           break;
-         case 1:
-           strcpy (buf->release, "Windows XP");
-           break;
-         case 2:
-           strcpy (buf->release, "Windows Server 2003");
-           break;
-         default:
-           strcpy (buf->release, "Windows");
-           break;
-         }
-      else if (version.dwMajorVersion == 6)
+    case VER_PLATFORM_WIN32_NT:
+      is_server = version.wProductType != VER_NT_WORKSTATION;
+      switch ((version.dwMajorVersion << 8)
+             | version.dwMinorVersion)
        {
-         if (version.wProductType != VER_NT_WORKSTATION)
-           strcpy (buf->release, "Windows Server 2008");
-         else
-           switch (version.dwMinorVersion)
-             {
-             case 0:
-               strcpy (buf->release, "Windows Vista");
-               break;
-             case 1:
-             default: /* versions not yet known */
-               strcpy (buf->release, "Windows 7");
-               break;
-             }
+       case 0x500:
+         strcpy (buf->release, "Windows 2000");
+         break;
+       case 0x501:
+         strcpy (buf->release, "Windows XP");
+         break;
+       case 0x502:
+         strcpy (buf->release, "Windows Server 2003");
+         break;
+       case 0x600:
+         strcpy (buf->release,
+                 is_server ? "Windows Server 2008" : "Windows Vista");
+         break;
+       case 0x601:
+         strcpy (buf->release,
+                 is_server ? "Windows Server 2008R2" : "Windows 7");
+         break;
+       default: /* 3.5, 4.0, versions not yet known */
+         sprintf (buf->release, "Windows NT %s %u.%u",
+                  is_server ? "Server" : "Workstation",
+                  (unsigned int) version.dwMajorVersion,
+                  (unsigned int) version.dwMinorVersion);
+         break;
        }
-      else
-       strcpy (buf->release, "Windows");
-    }
-  else
-    {
+      break;
+
+    case VER_PLATFORM_WIN32_WINDOWS:
       /* Windows 95/98/ME.  */
       sprintf (buf->release, "Windows %s", super_version);
+      break;
+
+    case VER_PLATFORM_WIN32_CE:
+    default:
+      sprintf (buf->release, "Windows %s %u.%u",
+              super_version,
+              (unsigned int) version.dwMajorVersion,
+              (unsigned int) version.dwMinorVersion);
+      break;
     }
 
   strcpy (buf->version, version.szCSDVersion);
@@ -164,8 +171,21 @@ uname (struct utsname *buf)
        /* Windows NT or newer.  */
        switch (info.wProcessorArchitecture)
          {
-         case PROCESSOR_ARCHITECTURE_AMD64:
-           strcpy (buf->machine, "x86_64");
+         case PROCESSOR_ARCHITECTURE_MIPS:
+           strcpy (buf->machine, "MIPS");
+           break;
+         case PROCESSOR_ARCHITECTURE_ALPHA:
+         case PROCESSOR_ARCHITECTURE_ALPHA64:
+           strcpy (buf->machine, "Alpha");
+           break;
+         case PROCESSOR_ARCHITECTURE_PPC:
+           strcpy (buf->machine, "PowerPC");
+           break;
+         case PROCESSOR_ARCHITECTURE_SHX:
+           strcpy (buf->machine, "SH");
+           break;
+         case PROCESSOR_ARCHITECTURE_ARM:
+           strcpy (buf->machine, "ARM");
            break;
          case PROCESSOR_ARCHITECTURE_IA64:
            strcpy (buf->machine, "ia64");
@@ -176,6 +196,12 @@ uname (struct utsname *buf)
              buf->machine[1] =
                '0' + (info.wProcessorLevel <= 6 ? info.wProcessorLevel : 6);
            break;
+         case PROCESSOR_ARCHITECTURE_AMD64:
+           strcpy (buf->machine, "x86_64");
+           break;
+         case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
+           strcpy (buf->machine, "i686");
+           break;
          default:
            strcpy (buf->machine, "unknown");
            break;
@@ -184,22 +210,10 @@ uname (struct utsname *buf)
     else
       {
        /* Windows 95/98/ME.  */
-       switch (info.dwProcessorType)
-         {
-         case PROCESSOR_AMD_X8664:
-           strcpy (buf->machine, "x86_64");
-           break;
-         case PROCESSOR_INTEL_IA64:
-           strcpy (buf->machine, "ia64");
-           break;
-         default:
-           if (info.dwProcessorType % 100 == 86)
-             sprintf (buf->machine, "i%u",
-                      (unsigned int) info.dwProcessorType);
-           else
-             strcpy (buf->machine, "unknown");
-           break;
-         }
+       if (info.dwProcessorType % 100 == 86)
+         sprintf (buf->machine, "i%u", (unsigned int) info.dwProcessorType);
+       else
+         strcpy (buf->machine, "unknown");
       }
   }
 
-- 
1.6.2.5






reply via email to

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