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 */
#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);
}