diff options
author | William A. Rowe Jr <wrowe@apache.org> | 2009-12-18 07:03:34 +0000 |
---|---|---|
committer | William A. Rowe Jr <wrowe@apache.org> | 2009-12-18 07:03:34 +0000 |
commit | 5ca2b89f813b646eb6b7dec5740223fc3def900b (patch) | |
tree | 5ff73fc2e68e88d9954de92b6ec156fa3995b850 /passwd | |
parent | 3b35e82c65acea5a684704e121edc9d2b9585640 (diff) | |
download | apr-5ca2b89f813b646eb6b7dec5740223fc3def900b.tar.gz |
Restructure to ensure successful mingw compilation, stdio seems very popular, too
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@892159 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'passwd')
-rw-r--r-- | passwd/apr_getpass.c | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/passwd/apr_getpass.c b/passwd/apr_getpass.c index 3deb08fc0..20e8738f7 100644 --- a/passwd/apr_getpass.c +++ b/passwd/apr_getpass.c @@ -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 @@ static char *get_password(const char *prompt) 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 @@ static char *get_password(const char *prompt) #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 */ |