From 778bc2efdc8835e73bd22a16dcb059634b2c2826 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 14 Jun 2017 10:10:32 +0200 Subject: invert condition --- bin/ykfde.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'bin') diff --git a/bin/ykfde.c b/bin/ykfde.c index 56e2e0c..96b5559 100644 --- a/bin/ykfde.c +++ b/bin/ykfde.c @@ -64,17 +64,14 @@ char * ask_secret(const char * text) { char * factor = NULL; size_t len; ssize_t readlen; - bool onTerminal = true; + bool onTerminal = false; /* get terminal properties */ - if (tcgetattr(STDIN_FILENO, &tp) < 0) { - onTerminal = false; - } else { + if (tcgetattr(STDIN_FILENO, &tp) == 0) { + onTerminal = true; tp_save = tp; - } - /* disable echo on terminal */ - if (onTerminal) { + /* disable echo on terminal */ tp.c_lflag &= ~ECHO; if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tp) < 0) { fprintf(stderr, "Failed setting terminal attributes.\n"); @@ -87,7 +84,7 @@ char * ask_secret(const char * text) { readlen = getline(&factor, &len, stdin); factor[readlen - 1] = '\0'; - if (onTerminal) { + if (onTerminal == true) { putchar('\n'); /* restore terminal */ -- cgit v1.2.3-54-g00ecf