2004-05-05 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Wed, 5 May 2004 18:18:58 +0000 (18:18 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Wed, 5 May 2004 18:18:58 +0000 (18:18 -0000)
* environment.c|h: Added icall ves_icall_System_Environment_
GetOSVersionString to get the current OS version as a string.
* icall.c: Registred icall.

svn path=/trunk/mono/; revision=26776

mono/metadata/ChangeLog
mono/metadata/environment.c
mono/metadata/environment.h
mono/metadata/icall.c

index 14607640c72f583f43c699037943af54ee6d5ddf..8986683f1a06187d589ed82baf51c8fc9b2048da 100644 (file)
@@ -1,3 +1,9 @@
+2004-05-05  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * environment.c|h: Added icall ves_icall_System_Environment_
+       GetOSVersionString to get the current OS version as a string.
+       * icall.c: Registred icall.
+
 2004-05-05  Lluis Sanchez Gual  <lluis@ximian.com>
 
        * object.c: in mono_object_get_virtual_method(), take into account that
index f8406bc998a0fc26e8daf5aba39ef6f9643a0ab6..b70eb256419fdfb730be179c5bd3345ac704b6d7 100644 (file)
@@ -1,16 +1,24 @@
 /*
  * environment.c: System.Environment support internal calls
  *
- * Author:
+ * Authors:
  *     Dick Porter (dick@ximian.com)
+ *     Sebastien Pouliot (sebastien@ximian.com)
  *
  * (C) 2002 Ximian, Inc.
+ * (C) 2004 Novell (http://www.novell.com)
  */
 
 #include <config.h>
 #include <glib.h>
 
+#include <mono/metadata/appdomain.h>
 #include <mono/metadata/environment.h>
+#include <mono/metadata/exception.h>
+
+#ifndef PLATFORM_WIN32
+#include <sys/utsname.h>
+#endif
 
 static gint32 exitcode=0;
 
@@ -23,3 +31,35 @@ void mono_environment_exitcode_set (gint32 value)
 {
        exitcode=value;
 }
+
+/* note: we better manipulate the string in managed code (easier and safer) */
+MonoString*
+ves_icall_System_Environment_GetOSVersionString (void)
+{
+#ifdef PLATFORM_WIN32
+       OSVERSIONINFO verinfo;
+
+       MONO_ARCH_SAVE_REGS;
+
+       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);
+               return mono_string_new (mono_domain_get (), version);
+       }
+#else
+       struct utsname name;
+
+       MONO_ARCH_SAVE_REGS;
+
+       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");
+}
index 03ec4b5db9cc3683d5f2cbe0e1005147ac6a98d8..4749fa720f84e7c475cf37694378acf79ba0216f 100644 (file)
@@ -13,4 +13,6 @@
 extern gint32 mono_environment_exitcode_get (void);
 extern void mono_environment_exitcode_set (gint32 value);
 
+extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
+
 #endif /* _MONO_METADATA_ENVIRONMENT_H_ */
index 41fa516cf3a45d3c43d8d8affea1e4375be792b3..a973616ce9ef5672cbc56c26d02c4bce05219198 100644 (file)
@@ -5033,7 +5033,8 @@ static const IcallEntry environment_icalls [] = {
        {"GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable},
        {"GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames},
        {"GetLogicalDrivesInternal", ves_icall_System_Environment_GetLogicalDrives },
-       {"GetMachineConfigPath",        ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
+       {"GetMachineConfigPath", ves_icall_System_Configuration_DefaultConfig_get_machine_config_path},
+       {"GetOSVersionString", ves_icall_System_Environment_GetOSVersionString},
        {"GetWindowsFolderPath", ves_icall_System_Environment_GetWindowsFolderPath},
        {"get_ExitCode", mono_environment_exitcode_get},
        {"get_HasShutdownStarted", ves_icall_System_Environment_get_HasShutdownStarted},