]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Detect windows platform correctly
authorNick Mathewson <nickm@torproject.org>
Wed, 19 Jan 2005 23:10:16 +0000 (23:10 +0000)
committerNick Mathewson <nickm@torproject.org>
Wed, 19 Jan 2005 23:10:16 +0000 (23:10 +0000)
svn:r3377

src/common/compat.c

index 69b82f8a4171f1fb1a4423925a2baf70aa2ff7f8..6a2be5fc09c003d4a29a77bcc7b5d9d69c2d4b8c 100644 (file)
@@ -542,8 +542,53 @@ get_uname(void)
     } else
 #endif
       {
+#ifdef MS_WINDOWS
+        OSVERSIONINFO info;
+        int i;
+        const char *plat = NULL;
+        static struct {
+          int major; int minor; const char *version;
+        } win_version_table[] = {
+          { 5, 2, "Windows Server 2003" },
+          { 5, 1, "Windows XP" },
+          { 5, 0, "Windows 2000" },
+          /* { 4, 0, "Windows NT 4.0" }, */
+          { 4, 90, "Windows Me" },
+          { 4, 10, "Windows 98" },
+          /* { 4, 0, "Windows 95" } */
+          { 3, 51, "Windows NT 3.51" },
+          { -1, -1, NULL }
+        };
+        info.dwOSVersionInfoSize = sizeof(info);
+        GetVersionEx(&info);
+        if (info.dwMajorVersion == 4 && info.dwMinorVersion == 0) {
+          if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
+            plat = "Windows NT 4.0";
+          else
+            plat = "Windows 95";
+        } else {
+          for (i=0; win_version_table[i].major>=0; ++i) {
+            if (win_version_table[i].major == info.dwMajorVersion &&
+                win_version_table[i].minor == info.dwMinorversion) {
+              plat = win_version_table[i].version;
+              break;
+            }
+          }
+        }
+        if (plat) {
+          strlcpy(uname_result, plat, sizeof(uname_result));
+        } else {
+          if (info.dwMajorVersion > 5 ||
+              (info.dwMajorVersion==5 && info.dwMinorVersion>2))
+            tor_snprintf("Very recent version of Windows [major=%d,minor=%d]",
+                         (int)info.dwMajorVersion,(int)info.dwMinorVersion);
+          else
+            tor_snprintf("Unrecognized version of Windows [major=%d,minor=%d]",
+                         (int)info.dwMajorVersion,(int)info.dwMinorVersion);
+        }
+#else
         strlcpy(uname_result, "Unknown platform", sizeof(uname_result));
-/* XXX win32 doesn't have uname, but we can still ifdef windows sprint "windows" */
+#endif
       }
     uname_result_is_set = 1;
   }