tcgetattr.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if(likely(retval == 0)) {
  37. termios_p->c_iflag = k_termios.c_iflag;
  38. termios_p->c_oflag = k_termios.c_oflag;
  39. termios_p->c_cflag = k_termios.c_cflag;
  40. termios_p->c_lflag = k_termios.c_lflag;
  41. termios_p->c_line = k_termios.c_line;
  42. #ifdef _HAVE_C_ISPEED
  43. termios_p->c_ispeed = k_termios.c_ispeed;
  44. #endif
  45. #ifdef _HAVE_C_OSPEED
  46. termios_p->c_ospeed = k_termios.c_ospeed;
  47. #endif
  48. if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
  49. || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
  50. {
  51. memset (mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  52. __KERNEL_NCCS * sizeof (cc_t)),
  53. _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
  54. #if 0
  55. memset ( (memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  56. __KERNEL_NCCS * sizeof (cc_t)) + (__KERNEL_NCCS * sizeof (cc_t))) ,
  57. _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
  58. #endif
  59. } else {
  60. size_t cnt;
  61. memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  62. __KERNEL_NCCS * sizeof (cc_t));
  63. for (cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
  64. termios_p->c_cc[cnt] = _POSIX_VDISABLE;
  65. }
  66. }
  67. return retval;
  68. }
  69. libc_hidden_def(tcgetattr)