Movatterモバイル変換


[0]ホーム

URL:


{-# LINE1"System/Environment/Blank.hsc"#-}{-# LANGUAGE Safe #-}{-# LANGUAGE CPP #-}{-# LANGUAGE CApiFFI #-}------------------------------------------------------------------------------- |-- Module      :  System.Environment.Blank-- Copyright   :  (c) Habib Alamin 2017-- License     :  BSD-style (see the file libraries/base/LICENSE)---- Maintainer  :  libraries@haskell.org-- Stability   :  provisional-- Portability :  portable---- A setEnv implementation that allows blank environment variables. Mimics-- the `System.Posix.Env` module from the @unix@ package, but with support-- for Windows too.---- The matrix of platforms that:----   * support @putenv("FOO")@ to unset environment variables,--   * support @putenv("FOO=")@ to unset environment variables or set them--     to blank values,--   * support @unsetenv@ to unset environment variables,--   * support @setenv@ to set environment variables,--   * etc.---- is very complicated. Some platforms don't support unsetting of environment-- variables at all.-------------------------------------------------------------------------------moduleSystem.Environment.Blank(moduleSystem.Environment,getEnv,getEnvDefault,setEnv,unsetEnv,)whereimportForeign.C{-# LINE48"System/Environment/Blank.hsc"#-}importSystem.Posix.Internals{-# LINE50"System/Environment/Blank.hsc"#-}importGHC.IO.ExceptionimportSystem.IO.ErrorimportControl.Exception.BaseimportData.MaybeimportSystem.Environment(getArgs,getProgName,getExecutablePath,withArgs,withProgName,getEnvironment){-# LINE65"System/Environment/Blank.hsc"#-}importqualifiedSystem.EnvironmentasEnvironment{-# LINE67"System/Environment/Blank.hsc"#-}-- TODO: include windows_cconv.h when it's merged, instead of duplicating-- this C macro block.{-# LINE79"System/Environment/Blank.hsc"#-}throwInvalidArgument::String->IOathrowInvalidArgumentfrom=throwIO(mkIOErrorInvalidArgumentfromNothingNothing)-- | Similar to 'System.Environment.lookupEnv'.getEnv::String->IO(MaybeString){-# LINE91"System/Environment/Blank.hsc"#-}getEnv=Environment.lookupEnv{-# LINE93"System/Environment/Blank.hsc"#-}-- | Get an environment value or a default value.getEnvDefault::String{- ^ variable name                    -}->String{- ^ fallback value                   -}->IOString{- ^ variable value or fallback value -}getEnvDefaultnamefallback=fromMaybefallback<$>getEnvname-- | Like 'System.Environment.setEnv', but allows blank environment values-- and mimics the function signature of 'System.Posix.Env.setEnv' from the-- @unix@ package.setEnv::String{- ^ variable name  -}->String{- ^ variable value -}->Bool{- ^ overwrite      -}->IO()setEnvkey_value_overwrite|nullkey=throwInvalidArgument"setEnv"|'='`elem`key=throwInvalidArgument"setEnv"|otherwise=ifoverwritethensetEnv_keyvalueelsedoenv_var<-getEnvkeycaseenv_varofJust_->return()Nothing->setEnv_keyvaluewherekey=takeWhile(/='\NUL')key_value=takeWhile(/='\NUL')value_setEnv_::String->String->IO(){-# LINE133"System/Environment/Blank.hsc"#-}setEnv_keyvalue=withFilePathkey$\keyP->withFilePathvalue$\valueP->throwErrnoIfMinus1_"setenv"$c_setenvkeyPvalueP(fromIntegral(fromEnumTrue))foreignimportccallunsafe"setenv"c_setenv::CString->CString->CInt->IOCInt{-# LINE142"System/Environment/Blank.hsc"#-}-- | Like 'System.Environment.unsetEnv', but allows for the removal of-- blank environment variables. May throw an exception if the underlying-- platform doesn't support unsetting of environment variables.unsetEnv::String->IO(){-# LINE163"System/Environment/Blank.hsc"#-}{-# LINE164"System/Environment/Blank.hsc"#-}unsetEnvname=withFilePathname$\s->throwErrnoIfMinus1_"unsetenv"(c_unsetenvs)-- POSIX.1-2001 compliant unsetenv(3)foreignimportcapiunsafe"HsBase.h unsetenv"c_unsetenv::CString->IOCInt{-# LINE177"System/Environment/Blank.hsc"#-}{-# LINE194"System/Environment/Blank.hsc"#-}

[8]ページ先頭

©2009-2025 Movatter.jp