c6c82ba743c0cae809e8db2621436f7ebb7013c7
[ghc-hetmet.git] / ghc / lib / std / cbits / tcSetAttr.c
1 /* 
2  * (c) The GHC Team 2001
3  *
4  * $Id: tcSetAttr.c,v 1.2 2001/01/26 17:51:40 rrt Exp $
5  *
6  * A wrapper around tcsetattr() which works for a background process.
7  */
8
9 #include "Rts.h"
10 #include "stgio.h"
11
12 #ifdef HAVE_SIGNAL_H
13 #include <signal.h>
14 #endif
15
16 #ifdef HAVE_TERMIOS_H
17 #include <termios.h>
18 #endif
19
20 #ifdef HAVE_UNISTD_H
21 #include <unistd.h>
22 #endif
23
24 #ifndef mingw32_TARGET_OS
25 /* tcsetattr() when invoked by a background process causes the process
26  * to be sent SIGTTOU regardless of whether the process has TOSTOP set
27  * in its terminal flags (try it...).  This function provides a
28  * wrapper which temporarily blocks SIGTTOU around the call, making it
29  * transparent.  */
30 int
31 tcSetAttr( int fd, int options, const struct termios *tp )
32 {
33     int res;
34     sigset_t block_ttou, old_sigset;
35     
36     sigemptyset (&block_ttou);
37     sigaddset (&block_ttou, SIGTTOU);
38     sigprocmask(SIG_BLOCK, &block_ttou, &old_sigset);
39     res = tcsetattr(fd, options, tp);
40     sigprocmask(SIG_SETMASK, &old_sigset, NULL);
41
42     return res;
43 }
44 #else
45 #define tcSetAttr(f,o,t) tcsetattr((f),(o),(t))
46 #endif