aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ian Lynagh <igloo@earth.li>2008-07-03 19:06:03 +0000
committerGravatar Ian Lynagh <igloo@earth.li>2008-07-03 19:06:03 +0000
commit3c5861c340cb45cf626f61e022d0aa2805f16569 (patch)
tree970791c9336c2dddc3d181b057b7603ae20d95f9
parent4981740456c7219251e9f059a509bc0e5cdf0930 (diff)
Allow C's unsetenv to return either void or int
Fixes, and patch from donn in, trac #2352.
-rw-r--r--System/Posix/Env.hsc7
-rw-r--r--configure.ac13
-rw-r--r--include/HsUnix.h10
3 files changed, 27 insertions, 3 deletions
diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc
index df7a3fe..39db08c 100644
--- a/System/Posix/Env.hsc
+++ b/System/Posix/Env.hsc
@@ -79,10 +79,11 @@ getEnvironment = do
unsetEnv :: String -> IO ()
#ifdef HAVE_UNSETENV
-unsetEnv name = withCString name c_unsetenv
+unsetEnv name = withCString name $ \ s ->
+ throwErrnoIfMinus1_ "unsetenv" (c_unsetenv s)
-foreign import ccall unsafe "unsetenv"
- c_unsetenv :: CString -> IO ()
+foreign import ccall unsafe "__hsunix_unsetenv"
+ c_unsetenv :: CString -> IO CInt
#else
unsetEnv name = putEnv (name ++ "=")
#endif
diff --git a/configure.ac b/configure.ac
index 97a3f2f..5283a55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,19 @@ case "$cv_func_usleep_return_type" in
;;
esac
+### POSIX.1003.1 unsetenv returns 0 or -1 (EINVAL), but older implementations
+### in common use return void.
+AC_CACHE_CHECK([return type of unsetenv], cv_func_unsetenv_return_type,
+ [AC_EGREP_HEADER(changequote(<, >)<void[ ]+unsetenv>changequote([, ]),
+ /usr/include/stdlib.h,
+ [cv_func_unsetenv_return_type=void],
+ [cv_func_unsetenv_return_type=int])])
+case "$cv_func_unsetenv_return_type" in
+ "void" )
+ AC_DEFINE([UNSETENV_RETURNS_VOID], [1], [Define if stdlib.h declares unsetenv to return void.])
+ ;;
+esac
+
dnl ** sometimes RTLD_NEXT is hidden in #ifdefs we really don't wan to set
AC_MSG_CHECKING(for RTLD_NEXT from dlfcn.h)
AC_EGREP_CPP(yes,
diff --git a/include/HsUnix.h b/include/HsUnix.h
index 7aee685..4afd51a 100644
--- a/include/HsUnix.h
+++ b/include/HsUnix.h
@@ -190,4 +190,14 @@ INLINE int __hscore_setrlimit(int resource, struct rlimit *rlim) {
}
#endif
+INLINE int __hsunix_unsetenv(const char *name)
+{
+#ifdef UNSETENV_RETURNS_VOID
+ unsetenv(name);
+ return 0;
+#else
+ return unsetenv(name);
+#endif
+}
+
#endif