Merge pull request #4938 from kumpera/optimize_ref_queries
[mono.git] / mono / tests / setenv.cs
1 using System;
2 using System.Runtime.InteropServices;
3
4 namespace Test {
5
6         public class Test {
7                 [DllImport("libc")]
8                 static extern int setenv(string name, string value, int overwrite);
9                 [DllImport("libc")]
10                 static extern IntPtr getenv(string name);
11
12                 static int Main() {
13                         try {
14                                 string name = "mono_test";
15                                 string value = "val";
16
17                                 setenv (name, value, 1);
18                                 string ret = Marshal.PtrToStringAnsi (getenv (name));
19
20                                 if (ret != value)
21                                         return 1;
22                         }
23                         catch (EntryPointNotFoundException) {
24                                 /* setenv is not available on some platforms */
25                         }
26                         catch (DllNotFoundException) {
27                                 /* libc might not be accessible by that name */
28                         }
29
30                         return 0;
31                 }
32         }
33 }