1 /* termios.cc: termios for WIN32.
3 Written by Doug Evans and Steve Chamberlain of Cygnus Support
4 dje@cygnus.com, sac@cygnus.com
6 This file is part of Cygwin.
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
13 #include "cygwin/version.h"
21 #include "perprocess.h"
24 /* tcsendbreak: POSIX 7.2.2.1 */
26 tcsendbreak (int fd
, int duration
)
30 cygheap_fdget
cfd (fd
);
36 else if ((res
= cfd
->bg_check (-SIGTTOU
)) > bg_eof
)
37 res
= cfd
->tcsendbreak (duration
);
40 syscall_printf ("%R = tcsendbreak(%d, %d)", res
, fd
, duration
);
44 /* tcdrain: POSIX 7.2.2.1 */
48 pthread_testcancel ();
52 termios_printf ("tcdrain");
54 cygheap_fdget
cfd (fd
);
60 else if ((res
= cfd
->bg_check (-SIGTTOU
)) > bg_eof
)
61 res
= cfd
->tcdrain ();
64 syscall_printf ("%R = tcdrain(%d)", res
, fd
);
68 /* tcflush: POSIX 7.2.2.1 */
70 tcflush (int fd
, int queue
)
74 cygheap_fdget
cfd (fd
);
80 else if (queue
!= TCIFLUSH
&& queue
!= TCOFLUSH
&& queue
!= TCIOFLUSH
)
82 else if ((res
= cfd
->bg_check (-SIGTTOU
)) > bg_eof
)
83 res
= cfd
->tcflush (queue
);
86 termios_printf ("%R = tcflush(%d, %d)", res
, fd
, queue
);
90 /* tcflow: POSIX 7.2.2.1 */
92 tcflow (int fd
, int action
)
96 cygheap_fdget
cfd (fd
);
102 else if ((res
= cfd
->bg_check (-SIGTTOU
)) > bg_eof
)
103 res
= cfd
->tcflow (action
);
106 syscall_printf ("%R = tcflow(%d, %d)", res
, fd
, action
);
110 /* tcsetattr: POSIX96 7.2.1.1 */
112 tcsetattr (int fd
, int a
, const struct termios
*t
)
115 int e
= get_errno ();
120 cygheap_fdget
cfd (fd
);
133 res
= cfd
->bg_check (-SIGTTOU
);
142 res
= cfd
->tcsetattr (a
, t
);
146 if (_my_tls
.call_signal_handler ())
158 termios_printf ("iflag %y, oflag %y, cflag %y, lflag %y, VMIN %d, VTIME %d",
159 t
->c_iflag
, t
->c_oflag
, t
->c_cflag
, t
->c_lflag
, t
->c_cc
[VMIN
],
161 termios_printf ("%R = tcsetattr(%d, %d, %p)", res
, fd
, a
, t
);
165 /* tcgetattr: POSIX 7.2.1.1 */
167 tcgetattr (int fd
, struct termios
*t
)
171 cygheap_fdget
cfd (fd
);
174 else if (!cfd
->is_tty ())
177 res
= cfd
->tcgetattr (t
);
180 termios_printf ("%R = tcgetattr(%d, %p)", res
, fd
, t
);
182 termios_printf ("iflag %y, oflag %y, cflag %y, lflag %y, VMIN %d, VTIME %d",
183 t
->c_iflag
, t
->c_oflag
, t
->c_cflag
, t
->c_lflag
, t
->c_cc
[VMIN
],
189 /* tcgetpgrp: POSIX 7.2.3.1 */
195 cygheap_fdget
cfd (fd
);
199 res
= cfd
->tcgetpgrp ();
201 termios_printf ("%R = tcgetpgrp(%d)", res
, fd
);
210 cygheap_fdget
cfd (fd
);
214 res
= cfd
->tcgetsid ();
216 termios_printf ("%R = tcgetsid(%d)", res
, fd
);
220 /* tcsetpgrp: POSIX 7.2.4.1 */
222 tcsetpgrp (int fd
, pid_t pgid
)
226 cygheap_fdget
cfd (fd
);
229 else if (!cfd
->is_tty ())
232 res
= cfd
->tcsetpgrp (pgid
);
234 termios_printf ("%R = tcsetpgrp(%d, %d)", res
, fd
, pgid
);
238 /* NIST PCTS requires not macro-only implementation */
244 /* cfgetospeed: POSIX96 7.1.3.1 */
246 cfgetospeed (const struct termios
*tp
)
251 /* cfgetispeed: POSIX96 7.1.3.1 */
253 cfgetispeed (const struct termios
*tp
)
259 setspeed (speed_t
&set_speed
, speed_t from_speed
)
295 set_speed
= from_speed
;
306 /* cfsetospeed: POSIX96 7.1.3.1 */
308 cfsetospeed (struct termios
*tp
, speed_t speed
)
310 return setspeed (tp
->c_ospeed
, speed
);
313 /* cfsetispeed: POSIX96 7.1.3.1 */
315 cfsetispeed (struct termios
*tp
, speed_t speed
)
317 return setspeed (tp
->c_ispeed
, speed
);
326 static const struct speed_struct speeds
[] =
353 { 1000000, B1000000
},
354 { 1152000, B1152000
},
355 { 1500000, B1500000
},
356 { 2000000, B2000000
},
357 { 2500000, B2500000
},
358 { 3000000, B3000000
},
361 /* Given a numerical baud rate (e.g., 9600), convert it to a Bnnn
362 constant (e.g., B9600). */
364 convert_speed (speed_t speed
)
366 for (size_t i
= 0; i
< sizeof speeds
/ sizeof speeds
[0]; i
++)
368 if (speed
== speeds
[i
].internal
)
370 else if (speed
== speeds
[i
].value
)
371 return speeds
[i
].internal
;
376 /* cfsetspeed: 4.4BSD */
377 /* Following Linux (undocumented), allow speed to be a numerical baud rate. */
379 cfsetspeed (struct termios
*tp
, speed_t speed
)
383 speed
= convert_speed (speed
);
384 /* errors come only from unsupported baud rates, so setspeed() would return
385 identical results in both calls */
386 if ((res
= setspeed (tp
->c_ospeed
, speed
)) == 0)
387 setspeed (tp
->c_ispeed
, speed
);
392 cfmakeraw(struct termios
*tp
)
394 tp
->c_iflag
&= ~(IGNBRK
| BRKINT
| PARMRK
| ISTRIP
395 | INLCR
| IGNCR
| ICRNL
| IXON
);
396 tp
->c_oflag
&= ~OPOST
;
397 tp
->c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| ISIG
| IEXTEN
);
398 tp
->c_cflag
&= ~(CSIZE
| PARENB
);