aboutsummaryrefslogtreecommitdiff
path: root/tests/termios/test_tcgetattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/termios/test_tcgetattr.c')
-rw-r--r--tests/termios/test_tcgetattr.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/termios/test_tcgetattr.c b/tests/termios/test_tcgetattr.c
new file mode 100644
index 00000000..2b3780ee
--- /dev/null
+++ b/tests/termios/test_tcgetattr.c
@@ -0,0 +1,61 @@
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+static void create_file(const char *path, const char *buffer, int mode) {
+ int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
+ assert(fd >= 0);
+
+ int err = write(fd, buffer, sizeof(char) * strlen(buffer));
+ assert(err == (sizeof(char) * strlen(buffer)));
+
+ close(fd);
+}
+
+void setup() {
+ create_file("test.txt", "abcdefg", 0666);
+}
+
+void cleanup() {
+ unlink("test.txt");
+}
+
+void test() {
+ struct termios tc;
+ int ret;
+ int fd;
+
+ fd = open("test.txt", O_RDONLY);
+
+ ret = tcgetattr(fd, &tc);
+ assert(ret == -1);
+ assert(errno = ENOTTY);
+
+ ret = tcgetattr(STDIN_FILENO, &tc);
+ assert(!ret);
+
+ ret = tcsetattr(fd, 0, &tc);
+ assert(ret == -1);
+ assert(errno = ENOTTY);
+
+ ret = tcsetattr(STDIN_FILENO, 0, &tc);
+ assert(!ret);
+
+ close(fd);
+
+ puts("success");
+}
+
+int main() {
+ atexit(cleanup);
+ signal(SIGABRT, cleanup);
+ setup();
+ test();
+ return EXIT_SUCCESS;
+}