system-posix-redirect 1.0.0.1 → 1.1
raw patch · 2 files changed
+12/−13 lines, 2 filesdep +bytestringPVP ok
version bump matches the API change (PVP)
Dependencies added: bytestring
API changes (from Hackage documentation)
- System.Posix.Redirect: redirectStderr :: IO a -> IO (String, a)
+ System.Posix.Redirect: redirectStderr :: IO a -> IO (ByteString, a)
- System.Posix.Redirect: redirectStdout :: IO a -> IO (String, a)
+ System.Posix.Redirect: redirectStdout :: IO a -> IO (ByteString, a)
- System.Posix.Redirect: redirectWriteHandle :: Fd -> Handle -> Ptr FILE -> IO a -> IO (String, a)
+ System.Posix.Redirect: redirectWriteHandle :: Fd -> Handle -> Ptr FILE -> IO a -> IO (ByteString, a)
- System.Posix.Redirect: unsafeRedirectWriteFd :: Fd -> IO a -> IO (String, a)
+ System.Posix.Redirect: unsafeRedirectWriteFd :: Fd -> IO a -> IO (ByteString, a)
Files
- System/Posix/Redirect.hs +10/−11
- system-posix-redirect.cabal +2/−2
System/Posix/Redirect.hs view
@@ -41,6 +41,8 @@ import Foreign import Foreign.C.Types +import Data.ByteString as BS+ import Control.Concurrent import Control.Exception @@ -53,7 +55,7 @@ -- descriptor is restored. Use with care: if there are any file -- handles with this descriptor that have unflushed buffers, they will -- not flush to the old file descriptor, but the new file descriptor.-unsafeRedirectWriteFd :: Fd -> IO a -> IO (String, a)+unsafeRedirectWriteFd :: Fd -> IO a -> IO (ByteString, a) unsafeRedirectWriteFd fd f = do -- setup (rfd, wfd) <- createPipe@@ -62,17 +64,14 @@ -- fork a thread to consume output outMVar <- newEmptyMVar outHandle <- fdToHandle rfd- out <- hGetContents outHandle- _ <- forkIO $ do- _ <- evaluate (length out)- putMVar outMVar ()+ _ <- forkIO (BS.hGetContents outHandle >>= putMVar outMVar) -- run the code r <- f -- cleanup dupTo_ old fd closeFd wfd -- wait for output- takeMVar outMVar+ out <- takeMVar outMVar hClose outHandle return (out, r) @@ -81,7 +80,7 @@ -- end of a pipe that @fd@ now points to. This function appropriately -- flushes the Haskell @oldHandle@ and the C @oldCHandle@ before -- and after @f@'s execution.-redirectWriteHandle :: Fd -> Handle -> Ptr FILE -> IO a -> IO (String, a)+redirectWriteHandle :: Fd -> Handle -> Ptr FILE -> IO a -> IO (ByteString, a) redirectWriteHandle oldFd oldHandle cOldHandle f = do hFlush oldHandle hFlush stdout@@ -92,16 +91,16 @@ _ <- c_fflush cOldHandle return r --- | @'redirectStdout f' redirects standard output during the execution+-- | @'redirectStdout' f@ redirects standard output during the execution -- of @f@ into a pipe passed as the first argument to @f@.-redirectStdout :: IO a -> IO (String, a)+redirectStdout :: IO a -> IO (ByteString, a) redirectStdout f = do c_stdout <- cio_stdout redirectWriteHandle stdOutput stdout c_stdout f --- | @'redirectStderr f' redirects standard error during the execution+-- | @'redirectStderr' f@ redirects standard error during the execution -- of @f@ into a pipe passed as the first argument to @f@.-redirectStderr :: IO a -> IO (String, a)+redirectStderr :: IO a -> IO (ByteString, a) redirectStderr f = do c_stderr <- cio_stderr redirectWriteHandle stdError stderr c_stderr f
system-posix-redirect.cabal view
@@ -1,5 +1,5 @@ Name: system-posix-redirect-Version: 1.0.0.1+Version: 1.1 Synopsis: A toy module that allows you to temporarily redirect a program's stdout. Description: Due to the design of POSIX, it is possible to@@ -33,7 +33,7 @@ Exposed-modules: System.Posix.Redirect Extensions: ForeignFunctionInterface, EmptyDataDecls- Build-depends: base >= 4 && < 5, unix >= 2.4.0+ Build-depends: base >= 4 && < 5, bytestring >= 0.9, unix >= 2.4.0 C-sources: cbits/hsredirect.c Include-dirs: include Install-includes: include/hsredirect.h