Back to index

glibc  2.9
tcgetattr.c
Go to the documentation of this file.
00001 /* Copyright (C) 1992,1995,1997,1998,2003,2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <errno.h>
00020 #include <string.h>
00021 #include <termios.h>
00022 #include <unistd.h>
00023 #include <sys/ioctl.h>
00024 #include <sys/types.h>
00025 #include <sysdep.h>
00026 
00027 /* The difference here is that the termios structure used in the
00028    kernel is not the same as we use in the libc.  Therefore we must
00029    translate it here.  */
00030 #include <kernel_termios.h>
00031 
00032 /* Put the state of FD into *TERMIOS_P.  */
00033 int
00034 __tcgetattr (fd, termios_p)
00035       int fd;
00036       struct termios *termios_p;
00037 {
00038   struct __kernel_termios k_termios;
00039   int retval;
00040 
00041   retval = INLINE_SYSCALL (ioctl, 3, fd, TCGETS, &k_termios);
00042 
00043   if (__builtin_expect (retval == 0, 1))
00044     {
00045       termios_p->c_iflag = k_termios.c_iflag;
00046       termios_p->c_oflag = k_termios.c_oflag;
00047       termios_p->c_cflag = k_termios.c_cflag;
00048       termios_p->c_lflag = k_termios.c_lflag;
00049       termios_p->c_line = k_termios.c_line;
00050 #ifdef _HAVE_STRUCT_TERMIOS_C_ISPEED
00051 # ifdef _HAVE_C_ISPEED
00052       termios_p->c_ispeed = k_termios.c_ispeed;
00053 # else
00054       termios_p->c_ispeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
00055 # endif
00056 #endif
00057 #ifdef _HAVE_STRUCT_TERMIOS_C_OSPEED
00058 # ifdef _HAVE_C_OSPEED
00059       termios_p->c_ospeed = k_termios.c_ospeed;
00060 # else
00061       termios_p->c_ospeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
00062 # endif
00063 #endif
00064       if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
00065          || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
00066        memset (__mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
00067                         __KERNEL_NCCS * sizeof (cc_t)),
00068               _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
00069       else
00070        {
00071          memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
00072                 __KERNEL_NCCS * sizeof (cc_t));
00073 
00074          for (size_t cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
00075            termios_p->c_cc[cnt] = _POSIX_VDISABLE;
00076        }
00077     }
00078 
00079   return retval;
00080 }
00081 
00082 weak_alias (__tcgetattr, tcgetattr)