tcgetattr.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /* The difference here is that the termios structure used in the
  22. kernel is not the same as we use in the libc. Therefore we must
  23. translate it here. */
  24. #include "kernel_termios.h"
  25. /* Put the state of FD into *TERMIOS_P. */
  26. int tcgetattr (int fd, struct termios *termios_p)
  27. {
  28. struct __kernel_termios k_termios;
  29. int retval;
  30. retval = ioctl (fd, TCGETS, &k_termios);
  31. if(likely(retval == 0)) {
  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. }
  62. return retval;
  63. }
  64. libc_hidden_def(tcgetattr)