浏览代码

Only set no buffering if we opened the file. Also, don't bother restoring
buffering since we will close the file in that case anyway.

Manuel Novoa III 24 年之前
父节点
当前提交
6fe5b769d6
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. 5 4
      libc/unistd/getpass.c

+ 5 - 4
libc/unistd/getpass.c

@@ -63,8 +63,11 @@ getpass (prompt)
       /* Tricky, tricky. */
       /* Tricky, tricky. */
       t.c_lflag &= ~(ECHO|ISIG);
       t.c_lflag &= ~(ECHO|ISIG);
       tty_changed = (tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0);
       tty_changed = (tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0);
-      /* Disable buffering for input FILE to prevent the buffering from flushing. */
-      setvbuf(in, NULL, _IOLBF, 0);
+      if (in != stdin) {
+	/* Disable buffering for read/write FILE to prevent problems with
+	 * fseek and buffering for read/write auto-transitioning. */
+	setvbuf(in, NULL, _IONBF, 0);
+      }
     }
     }
   else
   else
     tty_changed = 0;
     tty_changed = 0;
@@ -93,8 +96,6 @@ getpass (prompt)
   /* Restore the original setting.  */
   /* Restore the original setting.  */
   if (tty_changed) {
   if (tty_changed) {
     (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
     (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
-    /* Re-enable buffering. */
-    setlinebuf(in);
   }
   }
 
 
   if (in != stdin)
   if (in != stdin)