{-# LINE 1 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}
{-# LANGUAGE CApiFFI #-}
{-# LINE 3 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}
{-# LANGUAGE Safe #-}
{-# LINE 7 "libraries/unix/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 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}
import Foreign.C hiding (
throwErrnoPath,
throwErrnoPathIf,
throwErrnoPathIf_,
throwErrnoPathIfNull,
throwErrnoPathIfMinus1,
throwErrnoPathIfMinus1_ )
import System.Posix.ByteString.FilePath
{-# LINE 99 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}
getTerminalName :: Fd -> IO RawFilePath
getTerminalName :: Fd -> IO RawFilePath
getTerminalName (Fd CInt
fd) = do
Ptr CChar
s <- String -> IO (Ptr CChar) -> IO (Ptr CChar)
forall a. String -> IO (Ptr a) -> IO (Ptr a)
throwErrnoIfNull String
"getTerminalName" (CInt -> IO (Ptr CChar)
c_ttyname CInt
fd)
Ptr CChar -> IO RawFilePath
peekFilePath Ptr CChar
s
foreign import ccall unsafe "ttyname"
c_ttyname :: CInt -> IO CString
getControllingTerminalName :: IO RawFilePath
{-# LINE 123 "libraries/unix/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 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}
getSlaveTerminalName :: Fd -> IO RawFilePath
{-# LINE 141 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}
getSlaveTerminalName (Fd fd) = do
s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd)
peekFilePath s
{-# LINE 150 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}
foreign import capi unsafe "HsUnix.h ptsname"
c_ptsname :: CInt -> IO CString
{-# LINE 153 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}
{-# LINE 157 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}
openPseudoTerminal :: IO (Fd, Fd)
{-# LINE 167 "libraries/unix/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 "libraries/unix/System/Posix/Terminal/ByteString.hsc" #-}