tcgetattr.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  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. termios_p->c_iflag = k_termios.c_iflag;
  31. termios_p->c_oflag = k_termios.c_oflag;
  32. termios_p->c_cflag = k_termios.c_cflag;
  33. termios_p->c_lflag = k_termios.c_lflag;
  34. termios_p->c_line = k_termios.c_line;
  35. #ifdef _HAVE_C_ISPEED
  36. termios_p->c_ispeed = k_termios.c_ispeed;
  37. #endif
  38. #ifdef _HAVE_C_OSPEED
  39. termios_p->c_ospeed = k_termios.c_ospeed;
  40. #endif
  41. if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0
  42. || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1)
  43. memset ( (memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  44. __KERNEL_NCCS * sizeof (cc_t)) + (__KERNEL_NCCS * sizeof (cc_t))) ,
  45. _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
  46. else
  47. {
  48. size_t cnt;
  49. memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0],
  50. __KERNEL_NCCS * sizeof (cc_t));
  51. for (cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt)
  52. termios_p->c_cc[cnt] = _POSIX_VDISABLE;
  53. }
  54. return retval;
  55. }