1 /* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk> This
2 * file is part of the Linux-8086 C library and is distributed under the
3 * GNU Library General Public License.
6 /* Note: This is based loosely on the Glib termios routines. */
12 #include <sys/ioctl.h>
21 rv
= (ioctl(fd
, TCGETS
, &term
)==0);
22 if( rv
==0 && errno
== ENOSYS
)
35 return ioctl(fd
, TCGETS
, term
);
41 tcsetattr(fildes
, optional_actions
, termios_p
)
44 struct termios
*termios_p
;
46 switch (optional_actions
)
49 return ioctl(fildes
, TCSETS
, termios_p
);
51 return ioctl(fildes
, TCSETSW
, termios_p
);
53 return ioctl(fildes
, TCSETSF
, termios_p
);
62 /* Wait for pending output to be written on FD. */
67 /* With an argument of 1, TCSBRK just waits for output to drain. */
68 return ioctl(fd
, TCSBRK
, 1);
78 return ioctl(fd
, TCXONC
, action
);
83 /* Flush pending data on FD. */
85 tcflush(fd
, queue_selector
)
89 return ioctl(fd
, TCFLSH
, queue_selector
);
94 /* Send zero bits on FD. */
96 tcsendbreak(fd
, duration
)
101 * The break lasts 0.25 to 0.5 seconds if DURATION is zero, and an
102 * implementation-defined period if DURATION is nonzero. We define a
103 * positive DURATION to be number of milliseconds to break.
106 return ioctl(fd
, TCSBRK
, 0);
109 * ioctl can't send a break of any other duration for us. This could be
110 * changed to use trickery (e.g. lower speed and send a '\0') to send
111 * the break, but for now just return an error.
119 /* Set the foreground process group ID of FD set PGRP_ID. */
121 tcsetpgrp(fd
, pgrp_id
)
125 return ioctl(fd
, TIOCSPGRP
, &pgrp_id
);
130 /* Return the foreground process group ID of FD. */
136 if (ioctl(fd
, TIOCGPGRP
, &pgrp
) < 0)
143 speed_t
cfgetospeed(tp
)
146 return (tp
->c_cflag
& CBAUD
);
151 speed_t
cfgetispeed(tp
)
154 return (tp
->c_cflag
& CBAUD
);
159 int cfsetospeed(tp
, speed
)
160 struct termios
*tp
; speed_t speed
;
163 if ((speed
& ~CBAUD
) ||
164 ((speed
& CBAUDEX
) && (speed
< B57600
|| speed
> B115200
)))
170 tp
->c_cflag
&= ~CBAUD
;
171 tp
->c_cflag
|= speed
;
178 int cfsetispeed(tp
, speed
)
179 struct termios
*tp
; speed_t speed
;
181 return cfsetospeed(tp
, speed
);
185 /* From linux libc-4.6.27 again */
187 /* Copyright (C) 1992 Free Software Foundation, Inc.
188 This file is part of the GNU C Library.*/
194 /* I changed it to the current form according to the suggestions
195 * from Bruce Evans. Thanks Bruce. Please report the problems to
196 * H.J. Lu (hlu@eecs.wsu.edu).
200 * I took out the bits commented out by #if 1...#else - RHP
203 /* VMIN = 0 means non-blocking for Linux */
204 t
->c_cc
[VMIN
] = 1; t
->c_cc
[VTIME
] = 1;
205 /* clear some bits with &= ~(bits), set others with |= */
206 t
->c_cflag
&= ~(CSIZE
|PARENB
|CSTOPB
);
207 t
->c_cflag
|= (CS8
|HUPCL
|CREAD
);
208 t
->c_iflag
&= ~(IGNBRK
|BRKINT
|PARMRK
|INPCK
|ISTRIP
);
209 t
->c_iflag
&= ~(INLCR
|IGNCR
|ICRNL
|IXON
|IXOFF
);
210 t
->c_iflag
|= (BRKINT
|IGNPAR
);
211 t
->c_oflag
&= ~(OPOST
|OLCUC
|OCRNL
|ONOCR
|ONLRET
|OFILL
|OFDEL
);
212 t
->c_oflag
&= ~(NLDLY
|CRDLY
|TABDLY
|BSDLY
|VTDLY
|FFDLY
);
213 t
->c_oflag
|= (ONLCR
|NL0
|CR0
|TAB3
|BS0
|VT0
|FF0
);
214 t
->c_lflag
&= ~(ISIG
|ICANON
|IEXTEN
|ECHO
|ECHOE
|ECHOK
|ECHONL
);
215 t
->c_lflag
&= ~(NOFLSH
|XCASE
);
216 t
->c_lflag
&= ~(ECHOPRT
|ECHOCTL
|ECHOKE
);