4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1995 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * wrappers for posix tty manipulation functions
36 #include <sys/types.h>
39 * return the output speed from the struct
42 cfgetospeed(struct termios
*termios_p
)
44 return (termios_p
->c_cflag
& CBAUDEXT
?
45 (termios_p
->c_cflag
& CBAUD
) + CBAUD
+ 1 :
46 termios_p
->c_cflag
& CBAUD
);
50 * set the speed in the struct
53 cfsetospeed(struct termios
*termios_p
, speed_t speed
)
55 if (speed
> (2*CBAUD
+ 1)) {
60 termios_p
->c_cflag
|= CBAUDEXT
;
63 termios_p
->c_cflag
&= ~CBAUDEXT
;
66 (termios_p
->c_cflag
& ~CBAUD
) | (speed
& CBAUD
);
71 * return the input speed from the struct
74 cfgetispeed(struct termios
*termios_p
)
76 return (termios_p
->c_cflag
& CIBAUDEXT
?
77 ((termios_p
->c_cflag
& CIBAUD
) >> IBSHIFT
)
78 + (CIBAUD
>> IBSHIFT
) + 1 :
79 (termios_p
->c_cflag
& CIBAUD
) >> IBSHIFT
);
83 * set the input speed in the struct
86 cfsetispeed(struct termios
*termios_p
, speed_t speed
)
88 if (speed
> (2*CBAUD
+ 1)) {
92 if ((speed
<< IBSHIFT
) > CIBAUD
) {
93 termios_p
->c_cflag
|= CIBAUDEXT
;
94 speed
-= ((CIBAUD
>> IBSHIFT
) + 1);
96 termios_p
->c_cflag
&= ~CIBAUDEXT
;
98 (termios_p
->c_cflag
& ~CIBAUD
) | ((speed
<< IBSHIFT
) & CIBAUD
);
106 tcgetattr(int fd
, struct termios
*termios_p
)
108 return (ioctl(fd
, TCGETS
, termios_p
));
115 tcsetattr(int fd
, int option
, struct termios
*termios_p
)
117 struct termios work_area
;
119 /* If input speed is zero, set it to the output speed. */
120 if ((((termios_p
->c_cflag
>> IBSHIFT
) & CIBAUD
) == 0) &&
121 ((termios_p
->c_cflag
& CIBAUDEXT
) == 0)) {
122 work_area
= *termios_p
;
123 work_area
.c_cflag
|= (work_area
.c_cflag
& CBAUD
) << IBSHIFT
;
124 if (termios_p
->c_cflag
& CBAUDEXT
)
125 work_area
.c_cflag
|= CIBAUDEXT
;
126 termios_p
= &work_area
;
130 return (ioctl(fd
, TCSETSW
, termios_p
));
132 return (ioctl(fd
, TCSETSF
, termios_p
));
134 return (ioctl(fd
, TCSETS
, termios_p
));
144 * This is kludged for duration != 0; it should do something like crank the
145 * baud rate down and then send the break if the duration != 0.
148 tcsendbreak(int fd
, int duration
)
150 unsigned d
= (unsigned)duration
;
153 if (ioctl(fd
, TCSBRK
, 0) == -1)
160 * wait for all output to drain from fd
165 return (ioctl(fd
, TCSBRK
, !0));
172 tcflow(int fd
, int action
)
182 return (ioctl(fd
, TCXONC
, action
));
188 * flush read/write/both
191 tcflush(int fd
, int queue
)
200 return (ioctl(fd
, TCFLSH
, queue
));
206 * get the foreground process group id
213 if (ioctl(fd
, TIOCGETPGRP
, &grp_id
) == -1)
216 return ((pid_t
)grp_id
);
220 * set the foreground process group id
223 tcsetpgrp(int fd
, int grp_id
)
225 return (ioctl(fd
, TIOCSETPGRP
, &grp_id
));