1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2009
5 * TTY-related functionality
7 * ---------------------------------------------------------------------------*/
9 #include "PosixSource.h"
12 #include "RtsUtils.h" // __hscore_get/set prototypes
22 // Here we save the terminal settings on the standard file
23 // descriptors, if we need to change them (eg. to support NoBuffering
25 static void *saved_termios[3] = {NULL,NULL,NULL};
28 __hscore_get_saved_termios(int fd)
30 return (0 <= fd && fd < (int)(sizeof(saved_termios) / sizeof(*saved_termios))) ?
31 saved_termios[fd] : NULL;
35 __hscore_set_saved_termios(int fd, void* ts)
37 if (0 <= fd && fd < (int)(sizeof(saved_termios) / sizeof(*saved_termios))) {
38 saved_termios[fd] = ts;
43 resetTerminalSettings (void)
46 // Reset the terminal settings on the standard file descriptors,
47 // if we changed them. See System.Posix.Internals.tcSetAttr for
48 // more details, including the reason we termporarily disable
52 sigset_t sigset, old_sigset;
54 sigaddset(&sigset, SIGTTOU);
55 sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
56 for (fd = 0; fd <= 2; fd++) {
57 struct termios* ts = (struct termios*)__hscore_get_saved_termios(fd);
59 tcsetattr(fd,TCSANOW,ts);
62 sigprocmask(SIG_SETMASK, &old_sigset, NULL);