{-# LINE 1 "System/Posix/Terminal.hsc" #-}
{-# LANGUAGE CApiFFI #-}
{-# LINE 3 "System/Posix/Terminal.hsc" #-}
{-# LANGUAGE Safe #-}
{-# LINE 7 "System/Posix/Terminal.hsc" #-}
module System.Posix.Terminal (
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 Foreign.C
import System.Posix.Terminal.Common
import System.Posix.Types
{-# LINE 84 "System/Posix/Terminal.hsc" #-}
import System.Posix.Internals (peekFilePath)
{-# LINE 91 "System/Posix/Terminal.hsc" #-}
getTerminalName :: Fd -> IO FilePath
getTerminalName (Fd fd) = do
s <- throwErrnoIfNull "getTerminalName" (c_ttyname fd)
peekFilePath s
foreign import ccall unsafe "ttyname"
c_ttyname :: CInt -> IO CString
getControllingTerminalName :: IO FilePath
{-# LINE 115 "System/Posix/Terminal.hsc" #-}
getControllingTerminalName = do
s <- throwErrnoIfNull "getControllingTerminalName" (c_ctermid nullPtr)
peekFilePath s
foreign import capi unsafe "termios.h ctermid"
c_ctermid :: CString -> IO CString
{-# LINE 126 "System/Posix/Terminal.hsc" #-}
getSlaveTerminalName :: Fd -> IO FilePath
{-# LINE 133 "System/Posix/Terminal.hsc" #-}
getSlaveTerminalName (Fd fd) = do
s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd)
peekFilePath s
{-# LINE 142 "System/Posix/Terminal.hsc" #-}
foreign import capi unsafe "HsUnix.h ptsname"
c_ptsname :: CInt -> IO CString
{-# LINE 145 "System/Posix/Terminal.hsc" #-}
{-# LINE 149 "System/Posix/Terminal.hsc" #-}
openPseudoTerminal :: IO (Fd, Fd)
{-# LINE 159 "System/Posix/Terminal.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 219 "System/Posix/Terminal.hsc" #-}