aboutsummaryrefslogtreecommitdiffhomepage
path: root/System/Posix/Terminal/Common.hsc
diff options
context:
space:
mode:
authorGravatar Herbert Valerio Riedel <hvr@gnu.org>2016-01-30 16:46:56 +0100
committerGravatar Herbert Valerio Riedel <hvr@gnu.org>2016-01-30 16:56:57 +0100
commitd17b03d4d4525103f1995441045eae4c2c73355d (patch)
tree4fda6f1009df39f4a87b8cd9c7e887e6fc2f59e6 /System/Posix/Terminal/Common.hsc
parent4f3b5d8b87eef07d8df62a8d7240830bb81a8a6b (diff)
Don't assume `tcdrain` and `ctermid` exist always
This follows the scheme suggested in #24 This fixes #55
Diffstat (limited to 'System/Posix/Terminal/Common.hsc')
-rw-r--r--System/Posix/Terminal/Common.hsc16
1 files changed, 15 insertions, 1 deletions
diff --git a/System/Posix/Terminal/Common.hsc b/System/Posix/Terminal/Common.hsc
index 49418f5..4825b10 100644
--- a/System/Posix/Terminal/Common.hsc
+++ b/System/Posix/Terminal/Common.hsc
@@ -78,6 +78,11 @@ import Foreign.Storable ( Storable(..) )
import System.IO.Unsafe ( unsafePerformIO )
import System.Posix.Types
+#if !HAVE_TCDRAIN
+import System.IO.Error ( ioeSetLocation )
+import GHC.IO.Exception ( unsupportedOperation )
+#endif
+
-- -----------------------------------------------------------------------------
-- Terminal attributes
@@ -408,12 +413,21 @@ foreign import capi unsafe "termios.h tcsendbreak"
-- | @drainOutput fd@ calls @tcdrain@ to block until all output
-- written to @Fd@ @fd@ has been transmitted.
+--
+-- Throws 'IOError' (\"unsupported operation\") if platform does not
+-- provide @tcdrain(3)@ (use @#if HAVE_TCDRAIN@ CPP guard to
+-- detect availability).
drainOutput :: Fd -> IO ()
+#if HAVE_TCDRAIN
drainOutput (Fd fd) = throwErrnoIfMinus1_ "drainOutput" (c_tcdrain fd)
foreign import capi unsafe "termios.h tcdrain"
c_tcdrain :: CInt -> IO CInt
-
+#else
+{-# WARNING drainOutput
+ "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_TCDRAIN@)" #-}
+drainOutput _ = ioError (ioeSetLocation unsupportedOperation "drainOutput")
+#endif
data QueueSelector
= InputQueue -- TCIFLUSH