Fix to UriTemplate.Match to properly handle query parameters without a value. No...
[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  * Copyright 2002-2003 Ximian, Inc (http://www.ximian.com)
9  * Copyright 2004-2009 Novell, Inc (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/utils/mono-compiler.h>
19 #include <mono/io-layer/io-layer.h>
20
21 extern MonoString* ves_icall_System_Environment_GetOSVersionString (void) MONO_INTERNAL;
22
23 #if !defined(HOST_WIN32) && defined(HAVE_SYS_UTSNAME_H)
24 #include <sys/utsname.h>
25 #endif
26
27 static gint32 exitcode=0;
28
29 gint32 mono_environment_exitcode_get (void)
30 {
31         return(exitcode);
32 }
33
34 void mono_environment_exitcode_set (gint32 value)
35 {
36         exitcode=value;
37 }
38
39 /* note: we better manipulate the string in managed code (easier and safer) */
40 MonoString*
41 ves_icall_System_Environment_GetOSVersionString (void)
42 {
43 #ifdef HOST_WIN32
44         OSVERSIONINFOEX verinfo;
45
46         MONO_ARCH_SAVE_REGS;
47
48         verinfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
49         if (GetVersionEx ((OSVERSIONINFO*)&verinfo)) {
50                 char version [128];
51                 /* maximum string length is 45 bytes
52                    4 x 10 bytes per number, 1 byte for 0, 3 x 1 byte for dots, 1 for NULL */
53                 sprintf (version, "%ld.%ld.%ld.%d",
54                                  verinfo.dwMajorVersion,
55                                  verinfo.dwMinorVersion,
56                                  verinfo.dwBuildNumber,
57                                  verinfo.wServicePackMajor << 16);
58                 return mono_string_new (mono_domain_get (), version);
59         }
60 #elif defined(HAVE_SYS_UTSNAME_H)
61         struct utsname name;
62
63         MONO_ARCH_SAVE_REGS;
64
65         if (uname (&name) >= 0) {
66                 return mono_string_new (mono_domain_get (), name.release);
67         }
68 #endif
69         return mono_string_new (mono_domain_get (), "0.0.0.0");
70 }
71