From: Ian Lynagh Date: Sun, 22 Jul 2007 00:27:46 +0000 (+0000) Subject: Move throwErrnoPath* functions from unix:System.Posix.Error X-Git-Tag: 2007-09-13~29 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=285b5165a84bf796d7e1f655d73f458598ee569a;p=ghc-base.git Move throwErrnoPath* functions from unix:System.Posix.Error --- diff --git a/Foreign/C/Error.hs b/Foreign/C/Error.hs index dc450f3..7331bdd 100644 --- a/Foreign/C/Error.hs +++ b/Foreign/C/Error.hs @@ -448,6 +448,30 @@ throwErrnoIfNullRetry = throwErrnoIfRetry (== nullPtr) throwErrnoIfNullRetryMayBlock :: String -> IO (Ptr a) -> IO b -> IO (Ptr a) throwErrnoIfNullRetryMayBlock = throwErrnoIfRetryMayBlock (== nullPtr) +throwErrnoPath :: String -> FilePath -> IO a +throwErrnoPath loc path = + do + errno <- getErrno + ioError (errnoToIOError loc errno Nothing (Just path)) + +throwErrnoPathIf :: (a -> Bool) -> String -> FilePath -> IO a -> IO a +throwErrnoPathIf pred loc path f = + do + res <- f + if pred res then throwErrnoPath loc path else return res + +throwErrnoPathIf_ :: (a -> Bool) -> String -> FilePath -> IO a -> IO () +throwErrnoPathIf_ pred loc path f = void $ throwErrnoPathIf pred loc path f + +throwErrnoPathIfNull :: String -> FilePath -> IO (Ptr a) -> IO (Ptr a) +throwErrnoPathIfNull = throwErrnoPathIf (== nullPtr) + +throwErrnoPathIfMinus1 :: Num a => String -> FilePath -> IO a -> IO a +throwErrnoPathIfMinus1 = throwErrnoPathIf (== -1) + +throwErrnoPathIfMinus1_ :: Num a => String -> FilePath -> IO a -> IO () +throwErrnoPathIfMinus1_ = throwErrnoPathIf_ (== -1) + -- conversion of an "errno" value into IO error -- --------------------------------------------