2009-03-11 Zoltan Varga <vargaz@gmail.com>
[mono-debugger.git] / mono / metadata / environment.c
blob1c21cdbead61e7c35783ebe381aa5b1792251909
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/io-layer/io-layer.h>
20 #if !defined(PLATFORM_WIN32) && defined(HAVE_SYS_UTSNAME_H)
21 #include <sys/utsname.h>
22 #endif
24 static gint32 exitcode=0;
26 gint32 mono_environment_exitcode_get (void)
28 return(exitcode);
31 void mono_environment_exitcode_set (gint32 value)
33 exitcode=value;
36 /* note: we better manipulate the string in managed code (easier and safer) */
37 MonoString*
38 ves_icall_System_Environment_GetOSVersionString (void)
40 #ifdef PLATFORM_WIN32
41 OSVERSIONINFO verinfo;
43 MONO_ARCH_SAVE_REGS;
45 verinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
46 if (GetVersionEx (&verinfo)) {
47 char version [64];
48 /* maximum string length is 35 bytes
49 3 x 10 bytes per number, 1 byte for 0, 3 x 1 byte for dots, 1 for NULL */
50 sprintf (version, "%ld.%ld.%ld.0",
51 verinfo.dwMajorVersion,
52 verinfo.dwMinorVersion,
53 verinfo.dwBuildNumber);
54 return mono_string_new (mono_domain_get (), version);
56 #elif defined(HAVE_SYS_UTSNAME_H)
57 struct utsname name;
59 MONO_ARCH_SAVE_REGS;
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");