Blame sysdeps/unix/sysv/linux/tcgetattr.c

Packit 6c4009
/* Copyright (C) 1992-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <termios.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <sys/ioctl.h>
Packit 6c4009
#include <sys/types.h>
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
Packit 6c4009
/* The difference here is that the termios structure used in the
Packit 6c4009
   kernel is not the same as we use in the libc.  Therefore we must
Packit 6c4009
   translate it here.  */
Packit 6c4009
#include <kernel_termios.h>
Packit 6c4009
Packit 6c4009
/* Put the state of FD into *TERMIOS_P.  */
Packit 6c4009
int
Packit 6c4009
__tcgetattr (int fd, struct termios *termios_p)
Packit 6c4009
{
Packit 6c4009
  struct __kernel_termios k_termios;
Packit 6c4009
  int retval;
Packit 6c4009
Packit 6c4009
  retval = INLINE_SYSCALL (ioctl, 3, fd, TCGETS, &k_termios);
Packit 6c4009
Packit 6c4009
  if (__glibc_likely (retval == 0))
Packit 6c4009
    {
Packit 6c4009
      termios_p->c_iflag = k_termios.c_iflag;
Packit 6c4009
      termios_p->c_oflag = k_termios.c_oflag;
Packit 6c4009
      termios_p->c_cflag = k_termios.c_cflag;
Packit 6c4009
      termios_p->c_lflag = k_termios.c_lflag;
Packit 6c4009
      termios_p->c_line = k_termios.c_line;
Packit 6c4009
#ifdef _HAVE_STRUCT_TERMIOS_C_ISPEED
Packit 6c4009
# ifdef _HAVE_C_ISPEED
Packit 6c4009
      termios_p->c_ispeed = k_termios.c_ispeed;
Packit 6c4009
# else
Packit 6c4009
      termios_p->c_ispeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
#ifdef _HAVE_STRUCT_TERMIOS_C_OSPEED
Packit 6c4009
# ifdef _HAVE_C_OSPEED
Packit 6c4009
      termios_p->c_ospeed = k_termios.c_ospeed;
Packit 6c4009
# else
Packit 6c4009
      termios_p->c_ospeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
Packit 6c4009
# endif
Packit 6c4009
#endif
Packit 6c4009
      if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
Packit 6c4009
	  || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
Packit 6c4009
	memset (__mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
Packit 6c4009
			   __KERNEL_NCCS * sizeof (cc_t)),
Packit 6c4009
		_POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
Packit 6c4009
      else
Packit 6c4009
	{
Packit 6c4009
	  memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
Packit 6c4009
		  __KERNEL_NCCS * sizeof (cc_t));
Packit 6c4009
Packit 6c4009
	  for (size_t cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
Packit 6c4009
	    termios_p->c_cc[cnt] = _POSIX_VDISABLE;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return retval;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
libc_hidden_def (__tcgetattr)
Packit 6c4009
weak_alias (__tcgetattr, tcgetattr)