{-# LINE 1 "System/Posix/Terminal/PosixString.hsc" #-}
{-# LANGUAGE CApiFFI #-}
module System.Posix.Terminal.PosixString (
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 88 "System/Posix/Terminal/PosixString.hsc" #-}
import Foreign.C hiding (
throwErrnoPath,
throwErrnoPathIf,
throwErrnoPathIf_,
throwErrnoPathIfNull,
throwErrnoPathIfMinus1,
throwErrnoPathIfMinus1_ )
import System.OsPath.Types
import System.Posix.PosixPath.FilePath
{-# LINE 104 "System/Posix/Terminal/PosixString.hsc" #-}
getTerminalName :: Fd -> IO PosixPath
getTerminalName :: Fd -> IO PosixPath
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 PosixPath
peekFilePath Ptr CChar
s
foreign import ccall unsafe "ttyname"
c_ttyname :: CInt -> IO CString
getControllingTerminalName :: IO PosixPath
{-# LINE 128 "System/Posix/Terminal/PosixString.hsc" #-}
getControllingTerminalName = do
s <- throwErrnoIfNull "getControllingTerminalName" (c_ctermid nullPtr)
peekFilePath s
foreign import capi unsafe "termios.h ctermid"
c_ctermid :: CString -> IO CString
{-# LINE 139 "System/Posix/Terminal/PosixString.hsc" #-}
getSlaveTerminalName :: Fd -> IO PosixPath
{-# LINE 146 "System/Posix/Terminal/PosixString.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 157 "System/Posix/Terminal/PosixString.hsc" #-}
openPseudoTerminal :: IO (Fd, Fd)
{-# LINE 167 "System/Posix/Terminal/PosixString.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 218 "System/Posix/Terminal/PosixString.hsc" #-}