From 3c5861c340cb45cf626f61e022d0aa2805f16569 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Thu, 3 Jul 2008 19:06:03 +0000 Subject: Allow C's unsetenv to return either void or int Fixes, and patch from donn in, trac #2352. --- System/Posix/Env.hsc | 7 ++++--- configure.ac | 13 +++++++++++++ include/HsUnix.h | 10 ++++++++++ 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(<, >)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 -- cgit v1.2.3