3 * System.Environment support internal calls
6 * Dick Porter (dick@ximian.com)
7 * Sebastien Pouliot (sebastien@ximian.com)
9 * Copyright 2002-2003 Ximian, Inc (http://www.ximian.com)
10 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
11 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
17 #include <mono/metadata/appdomain.h>
18 #include <mono/metadata/environment.h>
19 #include <mono/metadata/exception.h>
20 #include <mono/metadata/handle.h>
21 #include <mono/utils/mono-compiler.h>
22 #include <mono/utils/w32api.h>
24 extern MonoStringHandle ves_icall_System_Environment_GetOSVersionString (MonoError *error);
26 #if !defined(HOST_WIN32) && defined(HAVE_SYS_UTSNAME_H)
27 #include <sys/utsname.h>
30 static gint32 exitcode=0;
33 * mono_environment_exitcode_get:
36 mono_environment_exitcode_get (void)
42 * mono_environment_exitcode_set:
45 mono_environment_exitcode_set (gint32 value)
50 /* note: we better manipulate the string in managed code (easier and safer) */
52 ves_icall_System_Environment_GetOSVersionString (MonoError *error)
56 OSVERSIONINFOEX verinfo;
58 verinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
59 if (GetVersionEx ((OSVERSIONINFO*)&verinfo)) {
61 /* maximum string length is 45 bytes
62 4 x 10 bytes per number, 1 byte for 0, 3 x 1 byte for dots, 1 for NULL */
63 sprintf (version, "%ld.%ld.%ld.%d",
64 verinfo.dwMajorVersion,
65 verinfo.dwMinorVersion,
66 verinfo.dwBuildNumber,
67 verinfo.wServicePackMajor << 16);
68 return mono_string_new_handle (mono_domain_get (), version, error);
70 #elif defined(HAVE_SYS_UTSNAME_H)
73 if (uname (&name) >= 0) {
74 return mono_string_new_handle (mono_domain_get (), name.release, error);
77 return mono_string_new_handle (mono_domain_get (), "0.0.0.0", error);