* roottypes.cs: Rename from tree.cs.
[mono.git] / mono / metadata / environment.c
1 /*
2  * environment.c: System.Environment support internal calls
3  *
4  * Authors:
5  *      Dick Porter (dick@ximian.com)
6  *      Sebastien Pouliot (sebastien@ximian.com)
7  *
8  * (C) 2002 Ximian, Inc.
9  * (C) 2004 Novell (http://www.novell.com)
10  */
11
12 #include <config.h>
13 #include <glib.h>
14
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>
19
20 #ifndef PLATFORM_WIN32
21 #include <sys/utsname.h>
22 #endif
23
24 static gint32 exitcode=0;
25
26 gint32 mono_environment_exitcode_get (void)
27 {
28         return(exitcode);
29 }
30
31 void mono_environment_exitcode_set (gint32 value)
32 {
33         exitcode=value;
34 }
35
36 /* note: we better manipulate the string in managed code (easier and safer) */
37 MonoString*
38 ves_icall_System_Environment_GetOSVersionString (void)
39 {
40 #ifdef PLATFORM_WIN32
41         OSVERSIONINFO verinfo;
42
43         MONO_ARCH_SAVE_REGS;
44
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);
55         }
56 #else
57         struct utsname name;
58
59         MONO_ARCH_SAVE_REGS;
60
61         if (uname (&name) == 0) {
62                 return mono_string_new (mono_domain_get (), name.release);
63         }
64 #endif
65         return mono_string_new (mono_domain_get (), "0.0.0.0");
66 }