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