tcsendbrk.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright (C) 1991-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 <signal.h>
  17. #include <termios.h>
  18. #include <unistd.h>
  19. #include "bsdtty.h"
  20. #include <sys/file.h>
  21. #include <sys/time.h>
  22. #include <sys/types.h>
  23. /* Send zero bits on FD. */
  24. int
  25. tcsendbreak (int fd, int duration)
  26. {
  27. struct timeval delay;
  28. /* The break lasts 0.25 to 0.5 seconds if DURATION is zero,
  29. and an implementation-defined period if DURATION is nonzero.
  30. We define a positive DURATION to be number of microseconds to break. */
  31. if (duration <= 0)
  32. duration = 400000;
  33. delay.tv_sec = 0;
  34. delay.tv_usec = duration;
  35. /* Starting sending break. */
  36. if (__ioctl (fd, TIOCSBRK, (void *) NULL) < 0)
  37. return -1;
  38. /* Wait DURATION microseconds. */
  39. (void) __select (0, (fd_set *) NULL, (fd_set *) NULL, (fd_set *) NULL,
  40. &delay);
  41. /* Turn off the break. */
  42. return __ioctl (fd, TIOCCBRK, (void *) NULL);
  43. }