tcgetattr.c 2.5 KB

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