.
[glibc-ports.git] / sysdeps / unix / sysv / aix / tcgetattr.c
blob01ffd55eff8b0f0e3214d6079c858abe3f9b1399
1 /* Copyright (C) 1992, 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <errno.h>
20 #include <stddef.h>
21 #include <sysv_termio.h>
22 #include <termios.h>
23 #include <sys/ioctl.h>
25 /* Put the state of FD into *TERMIOS_P. */
26 int
27 __tcgetattr (fd, termios_p)
28 int fd;
29 struct termios *termios_p;
31 struct __sysv_termio buf;
33 if (termios_p == NULL)
35 __set_errno (EINVAL);
36 return -1;
39 if (__ioctl (fd, _TCGETA, &buf) < 0)
40 return -1;
42 termios_p->c_cflag &= ~0x000f0000;
43 termios_p->c_cflag |= (termios_p->c_cflag & 0xf) << 16;
45 termios_p->c_iflag = 0;
46 if (buf.c_iflag & _SYSV_IGNBRK)
47 termios_p->c_iflag |= IGNBRK;
48 if (buf.c_iflag & _SYSV_BRKINT)
49 termios_p->c_iflag |= BRKINT;
50 if (buf.c_iflag & _SYSV_IGNPAR)
51 termios_p->c_iflag |= IGNPAR;
52 if (buf.c_iflag & _SYSV_PARMRK)
53 termios_p->c_iflag |= PARMRK;
54 if (buf.c_iflag & _SYSV_INPCK)
55 termios_p->c_iflag |= INPCK;
56 if (buf.c_iflag & _SYSV_ISTRIP)
57 termios_p->c_iflag |= ISTRIP;
58 if (buf.c_iflag & _SYSV_INLCR)
59 termios_p->c_iflag |= INLCR;
60 if (buf.c_iflag & _SYSV_IGNCR)
61 termios_p->c_iflag |= IGNCR;
62 if (buf.c_iflag & _SYSV_ICRNL)
63 termios_p->c_iflag |= ICRNL;
64 if (buf.c_iflag & _SYSV_IXON)
65 termios_p->c_iflag |= IXON;
66 if (buf.c_iflag & _SYSV_IXOFF)
67 termios_p->c_iflag |= IXOFF;
68 if (buf.c_iflag & _SYSV_IXANY)
69 termios_p->c_iflag |= IXANY;
70 if (buf.c_iflag & _SYSV_IMAXBEL)
71 termios_p->c_iflag |= IMAXBEL;
73 termios_p->c_oflag = 0;
74 if (buf.c_oflag & OPOST)
75 termios_p->c_oflag |= OPOST;
76 if (buf.c_oflag & ONLCR)
77 termios_p->c_oflag |= ONLCR;
78 termios_p->c_cflag = 0;
79 switch (buf.c_cflag & _SYSV_CSIZE)
81 case _SYSV_CS5:
82 termios_p->c_cflag |= CS5;
83 break;
84 case _SYSV_CS6:
85 termios_p->c_cflag |= CS6;
86 break;
87 case _SYSV_CS7:
88 termios_p->c_cflag |= CS7;
89 break;
90 case _SYSV_CS8:
91 termios_p->c_cflag |= CS8;
92 break;
94 if (buf.c_cflag & _SYSV_CSTOPB)
95 termios_p->c_cflag |= CSTOPB;
96 if (buf.c_cflag & _SYSV_CREAD)
97 termios_p->c_cflag |= CREAD;
98 if (buf.c_cflag & _SYSV_PARENB)
99 termios_p->c_cflag |= PARENB;
100 if (buf.c_cflag & _SYSV_PARODD)
101 termios_p->c_cflag |= PARODD;
102 if (buf.c_cflag & _SYSV_HUPCL)
103 termios_p->c_cflag |= HUPCL;
104 if (buf.c_cflag & _SYSV_CLOCAL)
105 termios_p->c_cflag |= CLOCAL;
106 termios_p->c_lflag = 0;
107 if (buf.c_lflag & _SYSV_ISIG)
108 termios_p->c_lflag |= ISIG;
109 if (buf.c_lflag & _SYSV_ICANON)
110 termios_p->c_lflag |= ICANON;
111 if (buf.c_lflag & _SYSV_ECHO)
112 termios_p->c_lflag |= ECHO;
113 if (buf.c_lflag & _SYSV_ECHOE)
114 termios_p->c_lflag |= ECHOE;
115 if (buf.c_lflag & _SYSV_ECHOK)
116 termios_p->c_lflag |= ECHOK;
117 if (buf.c_lflag & _SYSV_ECHONL)
118 termios_p->c_lflag |= ECHONL;
119 if (buf.c_lflag & _SYSV_NOFLSH)
120 termios_p->c_lflag |= NOFLSH;
121 if (buf.c_lflag & _SYSV_TOSTOP)
122 termios_p->c_lflag |= TOSTOP;
123 if (buf.c_lflag & _SYSV_ECHOKE)
124 termios_p->c_lflag |= ECHOKE;
125 if (buf.c_lflag & _SYSV_ECHOPRT)
126 termios_p->c_lflag |= ECHOPRT;
127 if (buf.c_lflag & _SYSV_ECHOCTL)
128 termios_p->c_lflag |= ECHOCTL;
129 if (buf.c_lflag & _SYSV_FLUSHO)
130 termios_p->c_lflag |= FLUSHO;
131 if (buf.c_lflag & _SYSV_PENDIN)
132 termios_p->c_lflag |= PENDIN;
133 if (buf.c_lflag & _SYSV_IEXTEN)
134 termios_p->c_lflag |= IEXTEN;
136 termios_p->c_cc[VEOF] = buf.c_cc[_SYSV_VEOF];
137 termios_p->c_cc[VEOL] = buf.c_cc[_SYSV_VEOL];
138 termios_p->c_cc[VEOL2] = buf.c_cc[_SYSV_VEOL2];
139 termios_p->c_cc[VERASE] = buf.c_cc[_SYSV_VERASE];
140 termios_p->c_cc[VKILL] = buf.c_cc[_SYSV_VKILL];
141 termios_p->c_cc[VINTR] = buf.c_cc[_SYSV_VINTR];
142 termios_p->c_cc[VQUIT] = buf.c_cc[_SYSV_VQUIT];
143 termios_p->c_cc[VSTART] = '\021'; /* XON (^Q). */
144 termios_p->c_cc[VSTOP] = '\023'; /* XOFF (^S). */
145 termios_p->c_cc[VSUSP] = '\0'; /* System V release 3 lacks job control. */
146 termios_p->c_cc[VMIN] = buf.c_cc[_SYSV_VMIN];
147 termios_p->c_cc[VTIME] = buf.c_cc[_SYSV_VTIME];
149 return 0;
152 weak_alias (__tcgetattr, tcgetattr)