{-# LINE 1 "System/Posix/Terminal/ByteString.hsc" #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE Safe #-}
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 80 "System/Posix/Terminal/ByteString.hsc" #-}
import Foreign.C hiding (
throwErrnoPath,
throwErrnoPathIf,
throwErrnoPathIf_,
throwErrnoPathIfNull,
throwErrnoPathIfMinus1,
throwErrnoPathIfMinus1_ )
import System.Posix.ByteString.FilePath
{-# LINE 95 "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 119 "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 130 "System/Posix/Terminal/ByteString.hsc" #-}
getSlaveTerminalName :: Fd -> IO RawFilePath
{-# LINE 137 "System/Posix/Terminal/ByteString.hsc" #-}
getSlaveTerminalName (Fd fd) = do
s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd)
peekFilePath s
foreign import capi unsafe "HsUnix.h ptsname"
c_ptsname :: CInt -> IO CString
{-# LINE 148 "System/Posix/Terminal/ByteString.hsc" #-}
openPseudoTerminal :: IO (Fd, Fd)
{-# LINE 158 "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 209 "System/Posix/Terminal/ByteString.hsc" #-}