aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Error.hs
diff options
context:
space:
mode:
authorGravatar simonmar <unknown>2004-08-19 11:15:52 +0000
committerGravatar simonmar <unknown>2004-08-19 11:15:52 +0000
commit2c0d5751ed3d29f7080e98c5fa94289727c5c11d (patch)
tree59386b7abea4d312eccc9c32545d2a77d8146b3a /System/Posix/Error.hs
parent2122158939042f99ef540967e5efcde256e7b458 (diff)
[project @ 2004-08-19 11:15:51 by simonmar]
Add filenames to all errors where it makes sense. I've added System.Posix.Error with a new family of error-throwing functions, throwErrnoPath*. This seemed to make the most sense: they don't belong in Foreign.C.Error (C by itself has no notion of paths). Fixes: [ 954378 ] getFileStatus does not include the file name in IO-Error
Diffstat (limited to 'System/Posix/Error.hs')
-rw-r--r--System/Posix/Error.hs50
1 files changed, 50 insertions, 0 deletions
diff --git a/System/Posix/Error.hs b/System/Posix/Error.hs
new file mode 100644
index 0000000..e42648a
--- /dev/null
+++ b/System/Posix/Error.hs
@@ -0,0 +1,50 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : System.Posix.Error
+-- Copyright : (c) The University of Glasgow 2002
+-- License : BSD-style (see the file libraries/base/LICENSE)
+--
+-- Maintainer : libraries@haskell.org
+-- Stability : provisional
+-- Portability : non-portable (requires POSIX)
+--
+-- POSIX error support
+--
+-----------------------------------------------------------------------------
+
+module System.Posix.Error (
+ throwErrnoPath,
+ throwErrnoPathIf,
+ throwErrnoPathIf_,
+ throwErrnoPathIfNull,
+ throwErrnoPathIfMinus1,
+ throwErrnoPathIfMinus1_
+ ) where
+
+import Foreign.C.Error
+import Foreign.Ptr
+import Foreign.Marshal.Error ( void )
+
+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)