tcgetattr.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (C) 1992, 1995, 1997, 1998 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. #include <string.h>
  16. #include <unistd.h>
  17. #include <sys/ioctl.h>
  18. #include <sys/types.h>
  19. /* The difference here is that the termios structure used in the
  20. kernel is not the same as we use in the libc. Therefore we must
  21. translate it here. */
  22. #include "kernel_termios.h"
  23. /* Put the state of FD into *TERMIOS_P. */
  24. int tcgetattr ( int fd, struct libc_termios *termios_p)
  25. {
  26. struct __kernel_termios k_termios;
  27. int retval;
  28. retval = ioctl (fd, TCGETS, &k_termios);
  29. termios_p->c_iflag = k_termios.c_iflag;
  30. termios_p->c_oflag = k_termios.c_oflag;
  31. termios_p->c_cflag = k_termios.c_cflag;
  32. termios_p->c_lflag = k_termios.c_lflag;
  33. termios_p->c_line = k_termios.c_line;
  34. #ifdef _HAVE_C_ISPEED
  35. termios_p->c_ispeed = k_termios.c_ispeed;
  36. #endif
  37. #ifdef _HAVE_C_OSPEED
  38. termios_p->c_ospeed = k_termios.c_ospeed;
  39. #endif
  40. if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
  41. || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
  42. memset ( (memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  43. __KERNEL_NCCS * sizeof (cc_t)) + (__KERNEL_NCCS * sizeof (cc_t))) ,
  44. _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
  45. else
  46. {
  47. size_t cnt;
  48. memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  49. __KERNEL_NCCS * sizeof (cc_t));
  50. for (cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
  51. termios_p->c_cc[cnt] = _POSIX_VDISABLE;
  52. }
  53. return retval;
  54. }