12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <termios.h>
- #include <errno.h>
- #include <string.h>
- const char *_progname;
- static int send_break(const char *port)
- {
- int err;
- int fd = open(port, O_RDWR|O_NOCTTY|O_NONBLOCK);
- if (fd < 0)
- goto fail;
- tcdrain(fd);
- do {
- err = tcsendbreak(fd, 0);
- } while (err && errno == EAGAIN);
- if (err)
- goto fail;
- close(fd);
- return 0;
- fail:
- fprintf(stderr, "%s: %s: %s\n", _progname, port, strerror(errno));
- if (fd >= 0)
- close(fd);
- return -1;
- }
- int main(int argc, char *argv[])
- {
- _progname = argv[0];
-
- if (argc != 2) {
- fprintf(stderr, "Usage: %s port\n", _progname);
- exit(1);
- }
- send_break(argv[1]);
- return 0;
- }
|