aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Env.hsc
diff options
context:
space:
mode:
authorGravatar stolz <unknown>2003-05-23 14:31:46 +0000
committerGravatar stolz <unknown>2003-05-23 14:31:46 +0000
commitb96d8bcac68ce335a8d8cf667d06c16f5613cde4 (patch)
tree83a84d0143f0dd78917bb4f529ce0a09304b49af /System/Posix/Env.hsc
parent131ff11bcda7e8adfd91669b0cb138ca964ef4f6 (diff)
[project @ 2003-05-23 14:31:46 by stolz]
No (un)setenv until SUSv3 (e.g. Solaris 2.9). (fallback untested)
Diffstat (limited to 'System/Posix/Env.hsc')
-rw-r--r--System/Posix/Env.hsc34
1 files changed, 22 insertions, 12 deletions
diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc
index 979b981..132d418 100644
--- a/System/Posix/Env.hsc
+++ b/System/Posix/Env.hsc
@@ -14,13 +14,13 @@
-----------------------------------------------------------------------------
module System.Posix.Env (
- getEnv,
- getEnvDefault,
- getEnvironmentPrim,
- getEnvironment,
- putEnv,
- setEnv,
- unsetEnv
+ getEnv
+ , getEnvDefault
+ , getEnvironmentPrim
+ , getEnvironment
+ , putEnv
+ , setEnv
+ , unsetEnv
) where
#include "HsUnix.h"
@@ -77,10 +77,15 @@ getEnvironment = do
-- from the environment.
unsetEnv :: String -> IO ()
+#ifdef HAVE_UNSETENV
+
unsetEnv name = withCString name c_unsetenv
foreign import ccall unsafe "unsetenv"
c_unsetenv :: CString -> IO ()
+#else
+unsetEnv name = putEnv (name ++ "=")
+#endif
-- |'putEnv' function takes an argument of the form @name=value@
-- and is equivalent to @setEnv(key,value,True{-overwrite-})@.
@@ -100,14 +105,19 @@ foreign import ccall unsafe "putenv"
-}
setEnv :: String -> String -> Bool {-overwrite-} -> IO ()
+#ifdef HAVE_SETENV
setEnv key value ovrwrt = do
withCString key $ \ keyP ->
withCString value $ \ valueP ->
- throwErrnoIfMinus1_ "putenv" $ c_setenv keyP valueP (toInt ovrwrt)
- where
- toInt :: Bool -> CInt
- toInt True = 1
- toInt False = 0
+ throwErrnoIfMinus1_ "putenv" $ c_setenv keyP valueP (fromEnum ovrwrt)
foreign import ccall unsafe "setenv"
c_setenv :: CString -> CString -> CInt -> IO CInt
+#else
+setEnv key value True = putEnv (key++"="++value)
+setEnv key value False = do
+ res <- getEnv key
+ case res of
+ Just _ -> return ()
+ Nothing -> putEnv (key++"="++value)
+#endif