Merge pull request #2202 from mono/revert-2090-mono-4.2.0-branch-bug25480
[mono-project.git] / mono / metadata / environment.c
blobe0d1970f61279e87374354b4bc734610cd344c9d
1 /*
2 * environment.c: System.Environment support internal calls
4 * Authors:
5 * Dick Porter (dick@ximian.com)
6 * Sebastien Pouliot (sebastien@ximian.com)
8 * Copyright 2002-2003 Ximian, Inc (http://www.ximian.com)
9 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
12 #include <config.h>
13 #include <glib.h>
15 #include <mono/metadata/appdomain.h>
16 #include <mono/metadata/environment.h>
17 #include <mono/metadata/exception.h>
18 #include <mono/utils/mono-compiler.h>
19 #include <mono/io-layer/io-layer.h>
21 extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
23 #if !defined(HOST_WIN32) && defined(HAVE_SYS_UTSNAME_H)
24 #include <sys/utsname.h>
25 #endif
27 static gint32 exitcode=0;
29 gint32 mono_environment_exitcode_get (void)
31 return(exitcode);
34 void mono_environment_exitcode_set (gint32 value)
36 exitcode=value;
39 /* note: we better manipulate the string in managed code (easier and safer) */
40 MonoString*
41 ves_icall_System_Environment_GetOSVersionString (void)
43 #ifdef HOST_WIN32
44 OSVERSIONINFOEX verinfo;
46 verinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
47 if (GetVersionEx ((OSVERSIONINFO*)&verinfo)) {
48 char version [128];
49 /* maximum string length is 45 bytes
50 4 x 10 bytes per number, 1 byte for 0, 3 x 1 byte for dots, 1 for NULL */
51 sprintf (version, "%ld.%ld.%ld.%d",
52 verinfo.dwMajorVersion,
53 verinfo.dwMinorVersion,
54 verinfo.dwBuildNumber,
55 verinfo.wServicePackMajor << 16);
56 return mono_string_new (mono_domain_get (), version);
58 #elif defined(HAVE_SYS_UTSNAME_H)
59 struct utsname name;
61 if (uname (&name) >= 0) {
62 return mono_string_new (mono_domain_get (), name.release);
64 #endif
65 return mono_string_new (mono_domain_get (), "0.0.0.0");