]> granicus.if.org Git - sudo/commitdiff
no more ioctl
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 1 Jul 1994 16:06:43 +0000 (16:06 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 1 Jul 1994 16:06:43 +0000 (16:06 +0000)
never returns NULL
uses fgets() and select() to timeout

tgetpass.c

index a9c11e883dbc1e517ec9ce251fda1c6af21ee7e4..028e221b5da890ba6b1954593d3beb8e0a60ad52 100644 (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);
 }