1 /* termios.cc: termios for WIN32.
3 Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
6 Written by Doug Evans and Steve Chamberlain of Cygnus Support
7 dje@cygnus.com, sac@cygnus.com
9 This file is part of Cygwin.
11 This software is a copyrighted work licensed under the terms of the
12 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
16 #include "cygwin/version.h"
24 #include "perprocess.h"
27 /* tcsendbreak: POSIX 7.2.2.1 */
29 tcsendbreak (int fd, int duration)
33 cygheap_fdget cfd (fd);
39 else if ((res = cfd->bg_check (-SIGTTOU)) > bg_eof)
40 res = cfd->tcsendbreak (duration);
43 syscall_printf ("%d = tcsendbreak (%d, %d)", res, fd, duration);
47 /* tcdrain: POSIX 7.2.2.1 */
51 pthread_testcancel ();
55 termios_printf ("tcdrain");
57 cygheap_fdget cfd (fd);
63 else if ((res = cfd->bg_check (-SIGTTOU)) > bg_eof)
64 res = cfd->tcdrain ();
67 syscall_printf ("%d = tcdrain (%d)", res, fd);
71 /* tcflush: POSIX 7.2.2.1 */
73 tcflush (int fd, int queue)
77 cygheap_fdget cfd (fd);
83 else if (queue != TCIFLUSH && queue != TCOFLUSH && queue != TCIOFLUSH)
85 else if ((res = cfd->bg_check (-SIGTTOU)) > bg_eof)
86 res = cfd->tcflush (queue);
89 termios_printf ("%d = tcflush (%d, %d)", res, fd, queue);
93 /* tcflow: POSIX 7.2.2.1 */
95 tcflow (int fd, int action)
99 cygheap_fdget cfd (fd);
105 else if ((res = cfd->bg_check (-SIGTTOU)) > bg_eof)
106 res = cfd->tcflow (action);
109 syscall_printf ("%d = tcflow (%d, %d)", res, fd, action);
113 /* tcsetattr: POSIX96 7.2.1.1 */
115 tcsetattr (int fd, int a, const struct termios *t)
118 t = __tonew_termios (t);
119 int e = get_errno ();
124 cygheap_fdget cfd (fd);
137 res = cfd->bg_check (-SIGTTOU);
146 res = cfd->tcsetattr (a, t);
150 if (_my_tls.call_signal_handler ())
153 /* fall through intentionally */
162 termios_printf ("iflag %p, oflag %p, cflag %p, lflag %p, VMIN %d, VTIME %d",
163 t->c_iflag, t->c_oflag, t->c_cflag, t->c_lflag, t->c_cc[VMIN],
165 termios_printf ("%d = tcsetattr (%d, %d, %x)", res, fd, a, t);
169 /* tcgetattr: POSIX 7.2.1.1 */
171 tcgetattr (int fd, struct termios *in_t)
174 struct termios *t = __makenew_termios (in_t);
176 cygheap_fdget cfd (fd);
179 else if (!cfd->is_tty ())
181 else if ((res = cfd->tcgetattr (t)) == 0)
182 __toapp_termios (in_t, t);
185 termios_printf ("%d = tcgetattr (%d, %p)", res, fd, in_t);
187 termios_printf ("iflag %x, oflag %x, cflag %x, lflag %x, VMIN %d, VTIME %d",
188 t->c_iflag, t->c_oflag, t->c_cflag, t->c_lflag, t->c_cc[VMIN],
194 /* tcgetpgrp: POSIX 7.2.3.1 */
200 cygheap_fdget cfd (fd);
204 res = cfd->tcgetpgrp ();
206 termios_printf ("%d = tcgetpgrp (%d)", res, fd);
215 cygheap_fdget cfd (fd);
219 res = cfd->tcgetsid ();
221 termios_printf ("%d = tcgetsid (%d)", res, fd);
225 /* tcsetpgrp: POSIX 7.2.4.1 */
227 tcsetpgrp (int fd, pid_t pgid)
231 cygheap_fdget cfd (fd);
234 else if (!cfd->is_tty ())
237 res = cfd->tcsetpgrp (pgid);
239 termios_printf ("%d = tcsetpgrp (%d, %d)", res, fd, pgid);
243 /* NIST PCTS requires not macro-only implementation */
249 /* cfgetospeed: POSIX96 7.1.3.1 */
251 cfgetospeed (const struct termios *tp)
253 return __tonew_termios (tp)->c_ospeed;
256 /* cfgetispeed: POSIX96 7.1.3.1 */
258 cfgetispeed (const struct termios *tp)
260 return __tonew_termios (tp)->c_ispeed;
264 setspeed (speed_t &set_speed, speed_t from_speed)
300 set_speed = from_speed;
311 /* cfsetospeed: POSIX96 7.1.3.1 */
313 cfsetospeed (struct termios *in_tp, speed_t speed)
315 struct termios *tp = __tonew_termios (in_tp);
316 int res = setspeed (tp->c_ospeed, speed);
317 __toapp_termios (in_tp, tp);
321 /* cfsetispeed: POSIX96 7.1.3.1 */
323 cfsetispeed (struct termios *in_tp, speed_t speed)
325 struct termios *tp = __tonew_termios (in_tp);
326 int res = setspeed (tp->c_ispeed, speed);
327 __toapp_termios (in_tp, tp);
332 cfmakeraw(struct termios *tp)
334 tp->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
335 | INLCR | IGNCR | ICRNL | IXON);
336 tp->c_oflag &= ~OPOST;
337 tp->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
338 tp->c_cflag &= ~(CSIZE | PARENB);