{-# LINE 1 "System/Posix/Terminal/ByteString.hsc" #-}
{-# LANGUAGE CApiFFI #-}
{-# LINE 3 "System/Posix/Terminal/ByteString.hsc" #-}
{-# LANGUAGE Safe #-}
{-# LINE 7 "System/Posix/Terminal/ByteString.hsc" #-}
module System.Posix.Terminal.ByteString (
TerminalAttributes,
getTerminalAttributes,
TerminalState(..),
setTerminalAttributes,
TerminalMode(..),
withoutMode,
withMode,
terminalMode,
bitsPerByte,
withBits,
ControlCharacter(..),
controlChar,
withCC,
withoutCC,
inputTime,
withTime,
minInput,
withMinInput,
BaudRate(..),
inputSpeed,
withInputSpeed,
outputSpeed,
withOutputSpeed,
sendBreak,
drainOutput,
QueueSelector(..),
discardData,
FlowAction(..),
controlFlow,
getTerminalProcessGroupID,
setTerminalProcessGroupID,
queryTerminal,
getTerminalName,
getControllingTerminalName,
openPseudoTerminal,
getSlaveTerminalName
) where
import Foreign
import System.Posix.Types
import System.Posix.Terminal.Common
{-# LINE 84 "System/Posix/Terminal/ByteString.hsc" #-}
import Foreign.C hiding (
throwErrnoPath,
throwErrnoPathIf,
throwErrnoPathIf_,
throwErrnoPathIfNull,
throwErrnoPathIfMinus1,
throwErrnoPathIfMinus1_ )
import System.Posix.ByteString.FilePath
{-# LINE 99 "System/Posix/Terminal/ByteString.hsc" #-}
getTerminalName :: Fd -> IO RawFilePath
getTerminalName (Fd fd) = do
s <- throwErrnoIfNull "getTerminalName" (c_ttyname fd)
peekFilePath s
foreign import ccall unsafe "ttyname"
c_ttyname :: CInt -> IO CString
getControllingTerminalName :: IO RawFilePath
{-# LINE 123 "System/Posix/Terminal/ByteString.hsc" #-}
getControllingTerminalName = do
s <- throwErrnoIfNull "getControllingTerminalName" (c_ctermid nullPtr)
peekFilePath s
foreign import capi unsafe "termios.h ctermid"
c_ctermid :: CString -> IO CString
{-# LINE 134 "System/Posix/Terminal/ByteString.hsc" #-}
getSlaveTerminalName :: Fd -> IO RawFilePath
{-# LINE 141 "System/Posix/Terminal/ByteString.hsc" #-}
getSlaveTerminalName (Fd fd) = do
s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd)
peekFilePath s
{-# LINE 150 "System/Posix/Terminal/ByteString.hsc" #-}
foreign import capi unsafe "HsUnix.h ptsname"
c_ptsname :: CInt -> IO CString
{-# LINE 153 "System/Posix/Terminal/ByteString.hsc" #-}
{-# LINE 157 "System/Posix/Terminal/ByteString.hsc" #-}
openPseudoTerminal :: IO (Fd, Fd)
{-# LINE 167 "System/Posix/Terminal/ByteString.hsc" #-}
openPseudoTerminal =
alloca $ \p_master ->
alloca $ \p_slave -> do
throwErrnoIfMinus1_ "openPty"
(c_openpty p_master p_slave nullPtr nullPtr nullPtr)
master <- peek p_master
slave <- peek p_slave
return (Fd master, Fd slave)
foreign import ccall unsafe "openpty"
c_openpty :: Ptr CInt -> Ptr CInt -> CString -> Ptr CTermios -> Ptr a
-> IO CInt
{-# LINE 227 "System/Posix/Terminal/ByteString.hsc" #-}