Updated to fedora-glibc-20041018T0940
[glibc.git] / sysdeps / unix / sysv / linux / tcgetattr.c
blob63453ca031b0903ba4dc9ecba69ae51e24357cec
1 /* Copyright (C) 1992, 1995, 1997, 1998, 2003 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 <string.h>
21 #include <termios.h>
22 #include <unistd.h>
23 #include <sys/ioctl.h>
24 #include <sys/types.h>
25 #include <sysdep.h>
27 /* The difference here is that the termios structure used in the
28 kernel is not the same as we use in the libc. Therefore we must
29 translate it here. */
30 #include <kernel_termios.h>
32 /* Put the state of FD into *TERMIOS_P. */
33 int
34 __tcgetattr (fd, termios_p)
35 int fd;
36 struct termios *termios_p;
38 struct __kernel_termios k_termios;
39 int retval;
41 retval = INLINE_SYSCALL (ioctl, 3, fd, TCGETS, &k_termios);
43 termios_p->c_iflag = k_termios.c_iflag;
44 termios_p->c_oflag = k_termios.c_oflag;
45 termios_p->c_cflag = k_termios.c_cflag;
46 termios_p->c_lflag = k_termios.c_lflag;
47 termios_p->c_line = k_termios.c_line;
48 #ifdef _HAVE_STRUCT_TERMIOS_C_ISPEED
49 # ifdef _HAVE_C_ISPEED
50 termios_p->c_ispeed = k_termios.c_ispeed;
51 # else
52 termios_p->c_ispeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
53 # endif
54 #endif
55 #ifdef _HAVE_STRUCT_TERMIOS_C_OSPEED
56 # ifdef _HAVE_C_OSPEED
57 termios_p->c_ospeed = k_termios.c_ospeed;
58 # else
59 termios_p->c_ospeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
60 # endif
61 #endif
62 if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
63 || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
64 memset (__mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
65 __KERNEL_NCCS * sizeof (cc_t)),
66 _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
67 else
69 size_t cnt;
71 memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
72 __KERNEL_NCCS * sizeof (cc_t));
74 for (cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
75 termios_p->c_cc[cnt] = _POSIX_VDISABLE;
78 return retval;
81 weak_alias (__tcgetattr, tcgetattr)