1 /* libc/sys/linux/termios.c - Terminal control */
2
3 /* Written 2000 by Werner Almesberger */
4
5
6 #include <errno.h>
7 #include <sys/types.h>
8 #include <sys/termios.h>
9 #include <sys/ioctl.h>
10
11
12 int
tcgetattr(int fd,struct termios * termios_p)13 tcgetattr(int fd,struct termios *termios_p)
14 {
15 return ioctl(fd,TCGETS,termios_p);
16 }
17
18
19 int
tcsetattr(int fd,int optional_actions,const struct termios * termios_p)20 tcsetattr(int fd,int optional_actions,const struct termios *termios_p)
21 {
22 int cmd;
23
24 switch (optional_actions) {
25 case TCSANOW:
26 cmd = TCSETS;
27 break;
28 case TCSADRAIN:
29 cmd = TCSETSW;
30 break;
31 case TCSAFLUSH:
32 cmd = TCSETSF;
33 break;
34 default:
35 errno = EINVAL;
36 return -1;
37 }
38 return ioctl(fd,cmd,termios_p);
39 }
40
41 #if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 4
42 pid_t
tcgetpgrp(int fd)43 tcgetpgrp(int fd)
44 {
45 int p;
46
47 if (ioctl(fd,TIOCGPGRP,&p) < 0)
48 return (pid_t)-1;
49 return (pid_t)p;
50 }
51
52
53 int
tcsetpgrp(int fd,pid_t pid)54 tcsetpgrp(int fd, pid_t pid)
55 {
56 int p = (int)pid;
57 return ioctl(fd,TIOCSPGRP,&p);
58 }
59 #endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 4 */
60
61 int
tcflow(int fd,int action)62 tcflow (int fd, int action)
63 {
64 return ioctl (fd, TCXONC, action);
65 }
66
67 int
tcflush(int fd,int queue_selector)68 tcflush (int fd, int queue_selector)
69 {
70 return ioctl (fd, TCFLSH, queue_selector);
71 }
72
73