summaryrefslogtreecommitdiff
path: root/Utility/Env.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-05-11 18:23:41 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-05-11 18:23:41 -0400
commit618af8b6772d25ab27336d240ecddae7ae207561 (patch)
tree9e48ea32c7cbe11603ab599b5e0616457cd4de4e /Utility/Env.hs
parentdb56fab07ddd6910b1dc08f4fa242c267c469eb5 (diff)
clean up from windows porting
Diffstat (limited to 'Utility/Env.hs')
-rwxr-xr-xUtility/Env.hs27
1 files changed, 22 insertions, 5 deletions
diff --git a/Utility/Env.hs b/Utility/Env.hs
index c6f051052..e1ab52415 100755
--- a/Utility/Env.hs
+++ b/Utility/Env.hs
@@ -10,28 +10,35 @@
module Utility.Env where
#ifdef __WINDOWS__
-import qualified System.Environment as E
import Utility.Exception
+import qualified System.Environment as E
#else
-import qualified System.Posix.Env as E
+import qualified System.Posix.Env as PE
#endif
{- Posix getEnv is faster than the one in System.Environment,
- so use when available. -}
getEnv :: String -> IO (Maybe String)
#ifndef __WINDOWS__
-getEnv = E.getEnv
+getEnv = PE.getEnv
#else
getEnv = catchMaybeIO . E.getEnv
#endif
getEnvDefault :: String -> String -> IO String
#ifndef __WINDOWS__
-getEnvDefault = E.getEnvDefault
+getEnvDefault = PE.getEnvDefault
#else
getEnvDefault var fallback = fromMaybe fallback <$> getEnv var
#endif
+getEnvironment :: IO [(String, String)]
+#ifndef __WINDOWS__
+getEnvironment = PE.getEnvironment
+#else
+getEnvironment = E.getEnvironment
+#endif
+
{- Returns True if it could successfully set the environment variable.
-
- There is, apparently, no way to do this in Windows. Instead,
@@ -39,8 +46,18 @@ getEnvDefault var fallback = fromMaybe fallback <$> getEnv var
setEnv :: String -> String -> Bool -> IO Bool
#ifndef __WINDOWS__
setEnv var val overwrite = do
- E.setEnv var val overwrite
+ PE.setEnv var val overwrite
return True
#else
setEnv _ _ _ = return False
#endif
+
+{- Returns True if it could successfully unset the environment variable. -}
+unsetEnv :: String -> IO Bool
+#ifndef __WINDOWS__
+unsetEnv var = do
+ PE.unsetEnv var
+ return True
+#else
+unsetEnv _ _ _ = return False
+#endif