From e94e7218b938ec9481a5c893365fe9a061d96d50 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 1 Jul 1994 16:06:43 +0000 Subject: [PATCH] no more ioctl never returns NULL uses fgets() and select() to timeout --- tgetpass.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tgetpass.c b/tgetpass.c index a9c11e883..028e221b5 100644 --- a/tgetpass.c +++ b/tgetpass.c @@ -157,20 +157,23 @@ char * tgetpass(prompt, timeout) /* return NULL if nothing to read by timeout */ #ifdef HAVE_SYSCONF - if (select(sysconf(_SC_OPEN_MAX), &readfds, NULL, NULL, &tv) <= 0) + if (select(sysconf(_SC_OPEN_MAX), &readfds, NULL, NULL, &tv) <= 0) { #else - if (select(getdtablesize(), &readfds, NULL, NULL, &tv) <= 0) + if (select(getdtablesize(), &readfds, NULL, NULL, &tv) <= 0) { #endif /* HAVE_SYSCONF */ - return(NULL); + buf[0] = '\0'; + goto cleanup; + } /* get the password */ - (void) ioctl(fileno(input), FIONBIO, 1); if (!fgets(buf, sizeof(buf), input)) - return(NULL); - (void) ioctl(fileno(input), FIONBIO, 0); + buf[0] = '\0'; + if (*(tmp = &buf[strlen(buf)-1]) == '\n') *tmp = '\0'; +cleanup: + /* turn on echo */ #ifdef HAVE_TERMIOS_H term.c_lflag = svflagval; @@ -203,8 +206,5 @@ char * tgetpass(prompt, timeout) if (input != stdin) (void) fclose(input); - if (buf[0]) - return(buf); - else - return(NULL); + return(buf); } -- 2.50.1