Skip to content
Snippets Groups Projects
Commit b2a695f3 authored by dterei's avatar dterei
Browse files

Use error not ioError for consistency.

parent 4b867e26
No related branches found
No related tags found
No related merge requests found
......@@ -23,9 +23,6 @@ module System.Posix.Temp (
#include "HsUnix.h"
#if !HAVE_MKSTEMPS
import Control.Exception (throwIO)
#endif
import Foreign.C
import System.IO
#if !HAVE_MKDTEMP
......@@ -93,8 +90,8 @@ foreign import ccall unsafe "HsUnix.h __hscore_mkstemps"
-- If you are using as system that doesn't support the mkstemps glibc function
-- (supported in glibc > 2.11) then this function simply throws an error.
mkstemps :: String -> String -> IO (FilePath, Handle)
mkstemps prefix suffix = do
#if HAVE_MKSTEMPS
mkstemps prefix suffix = do
let template = prefix ++ "XXXXXX" ++ suffix
lenOfsuf = (fromIntegral $ length suffix) :: CInt
withFilePath template $ \ ptr -> do
......@@ -103,7 +100,7 @@ mkstemps prefix suffix = do
h <- fdToHandle (Fd fd)
return (name, h)
#else
throwIO . userError $ "mkstemps: System does not have a mkstemp C function."
mkstemps = error "System.Posix.Temp.mkstemps: not available on this platform"
#endif
#if HAVE_MKDTEMP
......
......@@ -23,9 +23,6 @@ module System.Posix.Temp.ByteString (
#include "HsUnix.h"
#if !HAVE_MKSTEMPS
import Control.Exception (throwIO)
#endif
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
......@@ -78,8 +75,8 @@ foreign import ccall unsafe "HsUnix.h __hscore_mkstemps"
-- the created file, which contains 6 random characters in between
-- the prefix and suffix.
mkstemps :: ByteString -> ByteString -> IO (RawFilePath, Handle)
mkstemps prefix suffix = do
#if HAVE_MKSTEMPS
mkstemps prefix suffix = do
let template = prefix `B.append` (BC.pack "XXXXXX") `B.append` suffix
lenOfsuf = (fromIntegral $ B.length suffix) :: CInt
withFilePath template $ \ ptr -> do
......@@ -88,7 +85,7 @@ mkstemps prefix suffix = do
h <- fdToHandle (Fd fd)
return (name, h)
#else
throwIO . userError $ "mkstemps: System does not have a mkstemp C function."
mkstemps = error "System.Posix.Temp.mkstemps: not available on this platform"
#endif
#if HAVE_MKDTEMP
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment