xref: /haiku/src/tests/system/libroot/posix/termios.cpp (revision 6a2d53e7237764eab0c7b6d121772f26d636fb60)
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 
17 extern const char *__progname;
18 
19 
20 int
21 main(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