Merge pull request #2816 from xmcclure/profile-clean-0
[mono.git] / mono / metadata / environment.c
index d5525861fdbd82e67bb7976f8f950e6b7f7523ee..4726f9ba703db888ea33078bd842e31ccb88e294 100644 (file)
@@ -5,8 +5,9 @@
  *     Dick Porter (dick@ximian.com)
  *     Sebastien Pouliot (sebastien@ximian.com)
  *
- * (C) 2002 Ximian, Inc.
- * (C) 2004 Novell (http://www.novell.com)
+ * Copyright 2002-2003 Ximian, Inc (http://www.ximian.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/environment.h>
 #include <mono/metadata/exception.h>
+#include <mono/utils/mono-compiler.h>
 #include <mono/io-layer/io-layer.h>
 
-#ifndef PLATFORM_WIN32
+extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
+
+#if !defined(HOST_WIN32) && defined(HAVE_SYS_UTSNAME_H)
 #include <sys/utsname.h>
 #endif
 
@@ -37,30 +41,28 @@ void mono_environment_exitcode_set (gint32 value)
 MonoString*
 ves_icall_System_Environment_GetOSVersionString (void)
 {
-#ifdef PLATFORM_WIN32
-       OSVERSIONINFO verinfo;
-
-       MONO_ARCH_SAVE_REGS;
+#ifdef HOST_WIN32
+       OSVERSIONINFOEX verinfo;
 
-       verinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
-       if (GetVersionEx (&verinfo)) {
-               char version [64];
-               /* maximum string length is 35 bytes 
-                  3 x 10 bytes per number, 1 byte for 0, 3 x 1 byte for dots, 1 for NULL */
-               sprintf (version, "%ld.%ld.%ld.0", 
-                       verinfo.dwMajorVersion,
-                       verinfo.dwMinorVersion,
-                       verinfo.dwBuildNumber);
+       verinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
+       if (GetVersionEx ((OSVERSIONINFO*)&verinfo)) {
+               char version [128];
+               /* maximum string length is 45 bytes
+                  4 x 10 bytes per number, 1 byte for 0, 3 x 1 byte for dots, 1 for NULL */
+               sprintf (version, "%ld.%ld.%ld.%d",
+                                verinfo.dwMajorVersion,
+                                verinfo.dwMinorVersion,
+                                verinfo.dwBuildNumber,
+                                verinfo.wServicePackMajor << 16);
                return mono_string_new (mono_domain_get (), version);
        }
-#else
+#elif defined(HAVE_SYS_UTSNAME_H)
        struct utsname name;
 
-       MONO_ARCH_SAVE_REGS;
-
-       if (uname (&name) == 0) {
+       if (uname (&name) >= 0) {
                return mono_string_new (mono_domain_get (), name.release);
        }
 #endif
        return mono_string_new (mono_domain_get (), "0.0.0.0");
 }
+