no more ioctl

never returns NULL
uses fgets() and select() to timeout
This commit is contained in:
Todd C. Miller
1994-07-01 16:06:43 +00:00
parent 840b5688d4
commit e94e7218b9

View File

@@ -157,20 +157,23 @@ char * tgetpass(prompt, timeout)
/* return NULL if nothing to read by timeout */ /* return NULL if nothing to read by timeout */
#ifdef HAVE_SYSCONF #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 #else
if (select(getdtablesize(), &readfds, NULL, NULL, &tv) <= 0) if (select(getdtablesize(), &readfds, NULL, NULL, &tv) <= 0) {
#endif /* HAVE_SYSCONF */ #endif /* HAVE_SYSCONF */
return(NULL); buf[0] = '\0';
goto cleanup;
}
/* get the password */ /* get the password */
(void) ioctl(fileno(input), FIONBIO, 1);
if (!fgets(buf, sizeof(buf), input)) if (!fgets(buf, sizeof(buf), input))
return(NULL); buf[0] = '\0';
(void) ioctl(fileno(input), FIONBIO, 0);
if (*(tmp = &buf[strlen(buf)-1]) == '\n') if (*(tmp = &buf[strlen(buf)-1]) == '\n')
*tmp = '\0'; *tmp = '\0';
cleanup:
/* turn on echo */ /* turn on echo */
#ifdef HAVE_TERMIOS_H #ifdef HAVE_TERMIOS_H
term.c_lflag = svflagval; term.c_lflag = svflagval;
@@ -203,8 +206,5 @@ char * tgetpass(prompt, timeout)
if (input != stdin) if (input != stdin)
(void) fclose(input); (void) fclose(input);
if (buf[0]) return(buf);
return(buf);
else
return(NULL);
} }