From 552d3c4712734bad7553cc49f6f1e298548e5f05 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 15 Jul 2016 14:09:14 -0600 Subject: [PATCH] PTY: Fix a few errors from early testing --- examples/pty_test/Kconfig | 2 ++ examples/pty_test/pty_test.c | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/pty_test/Kconfig b/examples/pty_test/Kconfig index 69eb790e6..6a84d6309 100644 --- a/examples/pty_test/Kconfig +++ b/examples/pty_test/Kconfig @@ -6,6 +6,8 @@ config EXAMPLES_PTYTEST bool "Pseudo Terminal test example" default n + depends on PSEUDOTERM + select PSEUDOTERM_SUSV1 ---help--- Enable the PTY example diff --git a/examples/pty_test/pty_test.c b/examples/pty_test/pty_test.c index 087cfc977..0e7788d0e 100644 --- a/examples/pty_test/pty_test.c +++ b/examples/pty_test/pty_test.c @@ -71,18 +71,18 @@ int pty_test_main(int argc, char *argv[]) /* Grant access and unlock the slave device */ ret = grantpt(fd); - if (fd < 0) + if (ret < 0) { fprintf(stderr, "ERROR: grantpt() failed: %d\n", errno); - fclose(fd); + close(fd); return -1; } ret = unlockpt(fd); - if (fd < 0) + if (ret < 0) { fprintf(stderr, "ERROR: unlockpt() failed: %d\n", errno); - fclose(fd); + close(fd); return -1; } @@ -95,12 +95,14 @@ int pty_test_main(int argc, char *argv[]) for (; ; ) { - char buffer; - int in; + ssize_t nread; + char ch; - in = read(fd, &buffer, 1); - putchar(buffer); - buffer = '\0'; + nread = read(fd, &ch, 1); + UNUSED(nread); + + putchar(ch); + ch = '\0'; } return 0;