bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Windows port of getpass


From: Simon Josefsson
Subject: Windows port of getpass
Date: Tue, 24 Mar 2009 09:48:37 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.90 (gnu/linux)

Martin, Jim,

I can't get the Windows port of getpass in gnulib to work under Wine.
The call to _getch always return -1.  It works fine when run on native
Windows (XP) though.  Do you have any ideas?

I propose the patch below.  It will make the code fall back to getc when
_getch appears unusable (under Wine).  I've tested it under Wine and
Windows XP and it seems to work.

/Simon

diff --git a/lib/getpass.c b/lib/getpass.c
index 17d5137..0634ebb 100644
--- a/lib/getpass.c
+++ b/lib/getpass.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992-2001, 2003, 2004, 2005, 2006, 2007 Free Software
+/* Copyright (C) 1992-2001, 2003, 2004, 2005, 2006, 2007, 2009 Free Software
    Foundation, Inc.
 
    This file is part of the GNU C Library.
@@ -193,6 +193,7 @@ getpass (const char *prompt)
   char getpassbuf[PASS_MAX + 1];
   size_t i = 0;
   int c;
+  int use_getc = 0;
 
   if (prompt)
     {
@@ -202,8 +203,21 @@ getpass (const char *prompt)
 
   for (;;)
     {
-      c = _getch ();
-      if (c == '\r')
+      if (use_getc)
+       c = getc (stdin);
+      else
+       {
+         c = _getch ();
+         if (c == -1)
+           {
+             /* Under Wine, _getch always returns -1.  Fall back to
+                using getc.  */
+             use_getc = 1;
+             continue;
+           }
+       }
+
+      if (c == '\n' || c == '\r')
        {
          getpassbuf[i] = '\0';
          break;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]