about summary refs log tree commit diff
path: root/misc/getpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/getpass.c')
-rw-r--r--misc/getpass.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/misc/getpass.c b/misc/getpass.c
index 2caeb18668..0187ac4957 100644
--- a/misc/getpass.c
+++ b/misc/getpass.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 93, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -20,6 +20,11 @@
 #include <termios.h>
 #include <unistd.h>
 
+#ifdef USE_IN_LIBIO
+# define flockfile(s) _IO_flockfile (s)
+# define funlockfile(s) _IO_funlockfile (s)
+#endif
+
 /* It is desirable to use this bit on systems that have it.
    The only bit of terminal state we want to twiddle is echoing, which is
    done in software; there is no need to change the state of the terminal
@@ -52,9 +57,11 @@ getpass (prompt)
   else
     out = in;
 
+  flockfile (out);
+
   /* Turn echoing off if it is on now.  */
 
-  if (tcgetattr (fileno (in), &t) == 0)
+  if (__tcgetattr (fileno (in), &t) == 0)
     {
       /* Save the old one. */
       s = t;
@@ -66,8 +73,8 @@ getpass (prompt)
     tty_changed = 0;
 
   /* Write the prompt.  */
-  fputs (prompt, out);
-  fflush (out);
+  fputs_unlocked (prompt, out);
+  fflush_unlocked (out);
 
   /* Read the password.  */
   nread = __getline (&buf, &bufsize, in);
@@ -80,13 +87,15 @@ getpass (prompt)
 	buf[nread - 1] = '\0';
 	if (tty_changed)
 	  /* Write the newline that was not echoed.  */
-	  putc ('\n', out);
+	  putc_unlocked ('\n', out);
       }
 
   /* Restore the original setting.  */
   if (tty_changed)
     (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s);
 
+  funlockfile (out);
+
   if (in != stdin)
     /* We opened the terminal; now close it.  */
     fclose (in);