[project @ 2001-01-16 14:06:14 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / cbits / tcSetAttr.c
1 /* 
2  * (c) The GHC Team 2001
3  *
4  * $Id: tcSetAttr.c,v 1.1 2001/01/16 14:06:14 simonmar 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 /* tcsetattr() when invoked by a background process causes the process
25  * to be sent SIGTTOU regardless of whether the process has TOSTOP set
26  * in its terminal flags (try it...).  This function provides a
27  * wrapper which temporarily blocks SIGTTOU around the call, making it
28  * transparent.  */
29 int
30 tcSetAttr( int fd, int options, const struct termios *tp )
31 {
32     int res;
33     sigset_t block_ttou, old_sigset;
34     
35     sigemptyset (&block_ttou);
36     sigaddset (&block_ttou, SIGTTOU);
37     sigprocmask(SIG_BLOCK, &block_ttou, &old_sigset);
38     res = tcsetattr(fd, options, tp);
39     sigprocmask(SIG_SETMASK, &old_sigset, NULL);
40
41     return res;
42 }