aboutsummaryrefslogtreecommitdiffhomepage
path: root/System
diff options
context:
space:
mode:
authorGravatar Herbert Valerio Riedel <hvr@gnu.org>2016-01-31 12:57:23 +0100
committerGravatar Herbert Valerio Riedel <hvr@gnu.org>2016-01-31 12:57:23 +0100
commit57d2cb2a613e909829f22be6218e840b2b4602b5 (patch)
tree2f817405cccdd478c5a30f96bc4ce41743fffb2c /System
parentfb9b3eb74be56579deaa6e653686405e2e0463dd (diff)
Replace `__hsunix_unsetenv` wrapper with CApiFFI
Diffstat (limited to 'System')
-rw-r--r--System/Posix/Env.hsc15
-rw-r--r--System/Posix/Env/ByteString.hsc15
2 files changed, 24 insertions, 6 deletions
diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc
index 999daec..6412bae 100644
--- a/System/Posix/Env.hsc
+++ b/System/Posix/Env.hsc
@@ -1,3 +1,4 @@
+{-# LANGUAGE CApiFFI #-}
#if __GLASGOW_HASKELL__ >= 709
{-# LANGUAGE Safe #-}
#else
@@ -116,13 +117,21 @@ setEnvironment env = do
-- from the environment.
unsetEnv :: String -> IO ()
-#ifdef HAVE_UNSETENV
-
+#if HAVE_UNSETENV
+# if !UNSETENV_RETURNS_VOID
unsetEnv name = withFilePath name $ \ s ->
throwErrnoIfMinus1_ "unsetenv" (c_unsetenv s)
-foreign import ccall unsafe "__hsunix_unsetenv"
+-- POSIX.1-2001 compliant unsetenv(3)
+foreign import capi unsafe "HsUnix.h unsetenv"
c_unsetenv :: CString -> IO CInt
+# else
+unsetEnv name = withFilePath name c_unsetenv
+
+-- pre-POSIX unsetenv(3) returning @void@
+foreign import capi unsafe "HsUnix.h unsetenv"
+ c_unsetenv :: CString -> IO ()
+# endif
#else
unsetEnv name = putEnv (name ++ "=")
#endif
diff --git a/System/Posix/Env/ByteString.hsc b/System/Posix/Env/ByteString.hsc
index 0bbcfd8..57b03aa 100644
--- a/System/Posix/Env/ByteString.hsc
+++ b/System/Posix/Env/ByteString.hsc
@@ -1,3 +1,4 @@
+{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE Trustworthy #-}
#if __GLASGOW_HASKELL__ >= 709
{-# OPTIONS_GHC -fno-warn-trustworthy-safe #-}
@@ -98,13 +99,21 @@ getEnvironment = do
-- from the environment.
unsetEnv :: ByteString -> IO ()
-#ifdef HAVE_UNSETENV
-
+#if HAVE_UNSETENV
+# if !UNSETENV_RETURNS_VOID
unsetEnv name = B.useAsCString name $ \ s ->
throwErrnoIfMinus1_ "unsetenv" (c_unsetenv s)
-foreign import ccall unsafe "__hsunix_unsetenv"
+-- POSIX.1-2001 compliant unsetenv(3)
+foreign import capi unsafe "HsUnix.h unsetenv"
c_unsetenv :: CString -> IO CInt
+# else
+unsetEnv name = B.useAsCString name c_unsetenv
+
+-- pre-POSIX unsetenv(3) returning @void@
+foreign import capi unsafe "HsUnix.h unsetenv"
+ c_unsetenv :: CString -> IO ()
+# endif
#else
unsetEnv name = putEnv (name ++ "=")
#endif