1/*
2 * Copyright 2019, J��r��me Duval, jerome.duval@gmail.com.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <ctype.h>
8#include <errno.h>
9#include <fcntl.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <termios.h>
14#include <unistd.h>
15
16
17extern const char *__progname;
18
19
20int
21main(int argc, char **argv)
22{
23	if (argc < 2) {
24		fprintf(stderr, "usage: %s <file>\n", __progname);
25		return 1;
26	}
27
28	int fd = open(argv[1], O_RDONLY);
29	if (fd < 0) {
30		fprintf(stderr, "%s: could open the file read-only \"%s\": %s\n",
31			__progname, argv[1], strerror(errno));
32		return 1;
33	}
34	int err = tcdrain(fd);
35	if (err != -1 || errno != ENOTTY) {
36		fprintf(stderr, "%s: tcdrain didn't fail with ENOTTY \"%s\": %s\n",
37			__progname, argv[1], strerror(errno));
38		close(fd);
39		return 1;
40	}
41	err = tcflow(fd, TCION);
42	if (err != -1 || errno != ENOTTY) {
43		fprintf(stderr, "%s: tcflow didn't fail with ENOTTY \"%s\": %s\n",
44			__progname, argv[1], strerror(errno));
45		close(fd);
46		return 1;
47	}
48
49	err = tcflush(fd, TCIOFLUSH);
50	if (err != -1 || errno != ENOTTY) {
51		fprintf(stderr, "%s: tcflush didn't fail with ENOTTY \"%s\": %s\n",
52			__progname, argv[1], strerror(errno));
53		close(fd);
54		return 1;
55	}
56
57	close(fd);
58
59	return 0;
60}
61