apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r892159 - /apr/apr/trunk/passwd/apr_getpass.c
Date Fri, 18 Dec 2009 07:03:35 GMT
Author: wrowe
Date: Fri Dec 18 07:03:34 2009
New Revision: 892159

URL: http://svn.apache.org/viewvc?rev=892159&view=rev
Log:
Restructure to ensure successful mingw compilation, stdio seems very popular, too

Modified:
    apr/apr/trunk/passwd/apr_getpass.c

Modified: apr/apr/trunk/passwd/apr_getpass.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/passwd/apr_getpass.c?rev=892159&r1=892158&r2=892159&view=diff
==============================================================================
--- apr/apr/trunk/passwd/apr_getpass.c (original)
+++ apr/apr/trunk/passwd/apr_getpass.c Fri Dec 18 07:03:34 2009
@@ -47,6 +47,9 @@
 #if APR_HAVE_STRINGS_H
 #include <strings.h>
 #endif
+#if APR_HAVE_STDIO_H
+#include <stdio.h>
+#endif
 
 /* Disable getpass() support when PASS_MAX is defined and is "small",
  * for an arbitrary definition of "small". */
@@ -90,46 +93,7 @@
     return (char *) &password;
 }
 
-#elif defined (HAVE_TERMIOS_H)
-#include <stdio.h>
-
-static char *get_password(const char *prompt)
-{
-    struct termios attr;
-    static char password[MAX_STRING_LEN];
-    int n=0;
-    fputs(prompt, stderr);
-    fflush(stderr);
-
-    if (tcgetattr(STDIN_FILENO, &attr) != 0)
-        return NULL;
-    attr.c_lflag &= ~(ECHO);
-
-    if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) != 0)
-        return NULL;
-    while ((password[n] = getchar()) != '\n') {
-        if (n < sizeof(password) - 1 && password[n] >= ' ' && password[n]
<= '~') {
-            n++;
-        } else {
-            fprintf(stderr,"\n");
-            fputs(prompt, stderr);
-            fflush(stderr);
-            n = 0;
-        }
-    }
- 
-    password[n] = '\0';
-    printf("\n");
-    if (n > (MAX_STRING_LEN - 1)) {
-        password[MAX_STRING_LEN - 1] = '\0';
-    }
-
-    attr.c_lflag |= ECHO;
-    tcsetattr(STDIN_FILENO, TCSANOW, &attr);
-    return (char*) &password;
-}
-
-#else
+#elif defined(WIN32)
 
 /*
  * Windows lacks getpass().  So we'll re-implement it here.
@@ -200,6 +164,44 @@
 #endif
 }
 
+#elif defined (HAVE_TERMIOS_H)
+
+static char *get_password(const char *prompt)
+{
+    struct termios attr;
+    static char password[MAX_STRING_LEN];
+    int n=0;
+    fputs(prompt, stderr);
+    fflush(stderr);
+
+    if (tcgetattr(STDIN_FILENO, &attr) != 0)
+        return NULL;
+    attr.c_lflag &= ~(ECHO);
+
+    if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) != 0)
+        return NULL;
+    while ((password[n] = getchar()) != '\n') {
+        if (n < sizeof(password) - 1 && password[n] >= ' ' && password[n]
<= '~') {
+            n++;
+        } else {
+            fprintf(stderr,"\n");
+            fputs(prompt, stderr);
+            fflush(stderr);
+            n = 0;
+        }
+    }
+ 
+    password[n] = '\0';
+    printf("\n");
+    if (n > (MAX_STRING_LEN - 1)) {
+        password[MAX_STRING_LEN - 1] = '\0';
+    }
+
+    attr.c_lflag |= ECHO;
+    tcsetattr(STDIN_FILENO, TCSANOW, &attr);
+    return (char*) &password;
+}
+
 #endif /* no getchar or _getch */
 
 #endif /* no getpass or getpassphrase or getpass_r */



Mime
View raw message