From fb9b3eb74be56579deaa6e653686405e2e0463dd Mon Sep 17 00:00:00 2001 From: Herbert Valerio Riedel Date: Sun, 31 Jan 2016 12:34:59 +0100 Subject: Use CApiFFI for `ptsname(3)` et al for GHC>=8.0 This improves on 2ddf4b2b7bf41f878bc7d8a1afa49126710f524c --- System/Posix/Terminal.hsc | 15 +++++++++++++++ System/Posix/Terminal/ByteString.hsc | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'System') diff --git a/System/Posix/Terminal.hsc b/System/Posix/Terminal.hsc index c1b3ff8..0545f40 100644 --- a/System/Posix/Terminal.hsc +++ b/System/Posix/Terminal.hsc @@ -134,8 +134,14 @@ getSlaveTerminalName (Fd fd) = do s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd) peekFilePath s +# if __GLASGOW_HASKELL__ < 800 +-- see comment in cbits/HsUnix.c foreign import ccall unsafe "__hsunix_ptsname" c_ptsname :: CInt -> IO CString +# else +foreign import capi unsafe "HsUnix.h ptsname" + c_ptsname :: CInt -> IO CString +# endif #else getSlaveTerminalName _ = ioError (errnoToIOError "getSlaveTerminalName" eNOSYS Nothing Nothing) @@ -188,11 +194,20 @@ foreign import ccall unsafe "__hsunix_push_module" c_push_module :: CInt -> CString -> IO CInt #ifdef HAVE_PTSNAME +# if __GLASGOW_HASKELL__ < 800 +-- see comment in cbits/HsUnix.c foreign import ccall unsafe "__hsunix_grantpt" c_grantpt :: CInt -> IO CInt foreign import ccall unsafe "__hsunix_unlockpt" c_unlockpt :: CInt -> IO CInt +# else +foreign import capi unsafe "HsUnix.h grantpt" + c_grantpt :: CInt -> IO CInt + +foreign import capi unsafe "HsUnix.h unlockpt" + c_unlockpt :: CInt -> IO CInt +# endif #else c_grantpt :: CInt -> IO CInt c_grantpt _ = return (fromIntegral 0) diff --git a/System/Posix/Terminal/ByteString.hsc b/System/Posix/Terminal/ByteString.hsc index d98a9c0..cd6e200 100644 --- a/System/Posix/Terminal/ByteString.hsc +++ b/System/Posix/Terminal/ByteString.hsc @@ -142,8 +142,14 @@ getSlaveTerminalName (Fd fd) = do s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd) peekFilePath s +# if __GLASGOW_HASKELL__ < 800 +-- see comment in cbits/HsUnix.c foreign import ccall unsafe "__hsunix_ptsname" c_ptsname :: CInt -> IO CString +# else +foreign import capi unsafe "HsUnix.h ptsname" + c_ptsname :: CInt -> IO CString +# endif #else getSlaveTerminalName _ = ioError (errnoToIOError "getSlaveTerminalName" eNOSYS Nothing Nothing) @@ -195,12 +201,21 @@ pushModule (Fd fd) name = foreign import ccall unsafe "__hsunix_push_module" c_push_module :: CInt -> CString -> IO CInt -#ifdef HAVE_PTSNAME +#if HAVE_PTSNAME +# if __GLASGOW_HASKELL__ < 800 +-- see comment in cbits/HsUnix.c foreign import ccall unsafe "__hsunix_grantpt" c_grantpt :: CInt -> IO CInt foreign import ccall unsafe "__hsunix_unlockpt" c_unlockpt :: CInt -> IO CInt +# else +foreign import capi unsafe "HsUnix.h grantpt" + c_grantpt :: CInt -> IO CInt + +foreign import capi unsafe "HsUnix.h unlockpt" + c_unlockpt :: CInt -> IO CInt +# endif #else c_grantpt :: CInt -> IO CInt c_grantpt _ = return (fromIntegral (0::Int)) -- cgit v1.2.3