fix directive
[mono.git] / mono / tests / setenv.cs
index 63ad579fdc455755a08ab65ede9428b4784bd849..bd0d86eb0e4873fea7ab1c5a5d17b134122c8f3c 100644 (file)
@@ -7,17 +7,26 @@ namespace Test {
                [DllImport("libc")]
                static extern int setenv(string name, string value, int overwrite);
                [DllImport("libc")]
-               static extern string getenv(string name);
+               static extern IntPtr getenv(string name);
 
                static int Main() {
-                       string name = "mono_test";
-                       string value = "val";
+                       try {
+                               string name = "mono_test";
+                               string value = "val";
 
-                       setenv (name, value, 1);
-                       string ret = getenv (name);
+                               setenv (name, value, 1);
+                               string ret = Marshal.PtrToStringAnsi (getenv (name));
+
+                               if (ret != value)
+                                       return 1;
+                       }
+                       catch (EntryPointNotFoundException) {
+                               /* setenv is not available on some platforms */
+                       }
+                       catch (DllNotFoundException) {
+                               /* libc might not be accessible by that name */
+                       }
 
-                       if (ret != value)
-                               return 1;
                        return 0;
                }
        }