tcsetattr.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright (C) 1992-2019 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 <errno.h>
  15. #include <stddef.h>
  16. #include <termios.h>
  17. /* These are defined both in <bits/termios.h> and in <bits/ioctls.h>.
  18. They should have the same values, but perhaps not written the same way. */
  19. #undef ECHO
  20. #undef MDMBUF
  21. #undef TOSTOP
  22. #undef FLUSHO
  23. #undef PENDIN
  24. #undef NOFLSH
  25. #include <sys/ioctl.h>
  26. /* Set the state of FD to *TERMIOS_P. */
  27. int
  28. tcsetattr (int fd, int optional_actions, const struct termios *termios_p)
  29. {
  30. struct termios myt;
  31. if (optional_actions & TCSASOFT)
  32. {
  33. myt = *termios_p;
  34. myt.c_cflag |= CIGNORE;
  35. termios_p = &myt;
  36. optional_actions &= ~TCSASOFT;
  37. }
  38. switch (optional_actions)
  39. {
  40. case TCSANOW:
  41. return __ioctl (fd, TIOCSETA, termios_p);
  42. case TCSADRAIN:
  43. return __ioctl (fd, TIOCSETAW, termios_p);
  44. default:
  45. return __ioctl (fd, TIOCSETAF, termios_p);
  46. }
  47. }
  48. libc_hidden_def (tcsetattr)