tcgetattr.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the 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. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <features.h>
  16. #define __USE_GNU
  17. #include <string.h>
  18. #include <termios.h>
  19. #include <unistd.h>
  20. #include <sys/ioctl.h>
  21. #include <sys/types.h>
  22. /* The difference here is that the termios structure used in the
  23. kernel is not the same as we use in the libc. Therefore we must
  24. translate it here. */
  25. #include "kernel_termios.h"
  26. /* Put the state of FD into *TERMIOS_P. */
  27. int tcgetattr (int fd, struct termios *termios_p)
  28. {
  29. struct __kernel_termios k_termios;
  30. int retval;
  31. retval = ioctl (fd, TCGETS, &k_termios);
  32. termios_p->c_iflag = k_termios.c_iflag;
  33. termios_p->c_oflag = k_termios.c_oflag;
  34. termios_p->c_cflag = k_termios.c_cflag;
  35. termios_p->c_lflag = k_termios.c_lflag;
  36. termios_p->c_line = k_termios.c_line;
  37. #ifdef _HAVE_C_ISPEED
  38. termios_p->c_ispeed = k_termios.c_ispeed;
  39. #endif
  40. #ifdef _HAVE_C_OSPEED
  41. termios_p->c_ospeed = k_termios.c_ospeed;
  42. #endif
  43. if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
  44. || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
  45. {
  46. memset (mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  47. __KERNEL_NCCS * sizeof (cc_t)),
  48. _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
  49. #if 0
  50. memset ( (memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  51. __KERNEL_NCCS * sizeof (cc_t)) + (__KERNEL_NCCS * sizeof (cc_t))) ,
  52. _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
  53. #endif
  54. } else {
  55. size_t cnt;
  56. memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  57. __KERNEL_NCCS * sizeof (cc_t));
  58. for (cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
  59. termios_p->c_cc[cnt] = _POSIX_VDISABLE;
  60. }
  61. return retval;
  62. }