[docs] Update formatting in mono-api-jit.
[mono.git] / mono / metadata / environment.c
1 /**
2  * \file
3  * System.Environment support internal calls
4  *
5  * Authors:
6  *      Dick Porter (dick@ximian.com)
7  *      Sebastien Pouliot (sebastien@ximian.com)
8  *
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.
12  */
13
14 #include <config.h>
15 #include <glib.h>
16
17 #include <mono/metadata/appdomain.h>
18 #include <mono/metadata/environment.h>
19 #include <mono/metadata/exception.h>
20 #include <mono/utils/mono-compiler.h>
21 #include <mono/utils/w32api.h>
22
23 extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
24
25 #if !defined(HOST_WIN32) && defined(HAVE_SYS_UTSNAME_H)
26 #include <sys/utsname.h>
27 #endif
28
29 static gint32 exitcode=0;
30
31 /**
32  * mono_environment_exitcode_get:
33  */
34 gint32
35 mono_environment_exitcode_get (void)
36 {
37         return(exitcode);
38 }
39
40 /**
41  * mono_environment_exitcode_set:
42  */
43 void
44 mono_environment_exitcode_set (gint32 value)
45 {
46         exitcode=value;
47 }
48
49 /* note: we better manipulate the string in managed code (easier and safer) */
50 MonoString*
51 ves_icall_System_Environment_GetOSVersionString (void)
52 {
53 #ifdef HOST_WIN32
54         OSVERSIONINFOEX verinfo;
55
56         verinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
57         if (GetVersionEx ((OSVERSIONINFO*)&verinfo)) {
58                 char version [128];
59                 /* maximum string length is 45 bytes
60                    4 x 10 bytes per number, 1 byte for 0, 3 x 1 byte for dots, 1 for NULL */
61                 sprintf (version, "%ld.%ld.%ld.%d",
62                                  verinfo.dwMajorVersion,
63                                  verinfo.dwMinorVersion,
64                                  verinfo.dwBuildNumber,
65                                  verinfo.wServicePackMajor << 16);
66                 return mono_string_new (mono_domain_get (), version);
67         }
68 #elif defined(HAVE_SYS_UTSNAME_H)
69         struct utsname name;
70
71         if (uname (&name) >= 0) {
72                 return mono_string_new (mono_domain_get (), name.release);
73         }
74 #endif
75         return mono_string_new (mono_domain_get (), "0.0.0.0");
76 }
77