tcgetattr.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include <string.h>
  17. #include <termios.h>
  18. #include <unistd.h>
  19. #include <sys/ioctl.h>
  20. #include <sys/types.h>
  21. libc_hidden_proto(ioctl)
  22. /* Experimentally off - libc_hidden_proto(memset) */
  23. /* Experimentally off - libc_hidden_proto(memcpy) */
  24. /* Experimentally off - libc_hidden_proto(mempcpy) */
  25. libc_hidden_proto(tcgetattr)
  26. /* The difference here is that the termios structure used in the
  27. kernel is not the same as we use in the libc. Therefore we must
  28. translate it here. */
  29. #include "kernel_termios.h"
  30. /* Put the state of FD into *TERMIOS_P. */
  31. int tcgetattr (int fd, struct termios *termios_p)
  32. {
  33. struct __kernel_termios k_termios;
  34. int retval;
  35. retval = ioctl (fd, TCGETS, &k_termios);
  36. termios_p->c_iflag = k_termios.c_iflag;
  37. termios_p->c_oflag = k_termios.c_oflag;
  38. termios_p->c_cflag = k_termios.c_cflag;
  39. termios_p->c_lflag = k_termios.c_lflag;
  40. termios_p->c_line = k_termios.c_line;
  41. #ifdef _HAVE_C_ISPEED
  42. termios_p->c_ispeed = k_termios.c_ispeed;
  43. #endif
  44. #ifdef _HAVE_C_OSPEED
  45. termios_p->c_ospeed = k_termios.c_ospeed;
  46. #endif
  47. if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
  48. || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
  49. {
  50. memset (mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  51. __KERNEL_NCCS * sizeof (cc_t)),
  52. _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
  53. #if 0
  54. memset ( (memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  55. __KERNEL_NCCS * sizeof (cc_t)) + (__KERNEL_NCCS * sizeof (cc_t))) ,
  56. _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
  57. #endif
  58. } else {
  59. size_t cnt;
  60. memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  61. __KERNEL_NCCS * sizeof (cc_t));
  62. for (cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
  63. termios_p->c_cc[cnt] = _POSIX_VDISABLE;
  64. }
  65. return retval;
  66. }
  67. libc_hidden_def(tcgetattr)