]> git.saurik.com Git - apple/libc.git/blobdiff - gen/FreeBSD/readpassphrase.c
Libc-1082.50.1.tar.gz
[apple/libc.git] / gen / FreeBSD / readpassphrase.c
index d100be40852386a0b2ad29a4ec250a98dba1b2d4..3bd6a6a5fa63ef2d00ca032bee166e32f9b27776 100644 (file)
@@ -33,6 +33,8 @@ static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD: src/lib/libc/gen/readpassphrase.c,v 1.6 2002/03/09 03:16:41 green Exp $");
 
+#include "xlocale_private.h"
+
 #include "namespace.h"
 #include <ctype.h>
 #include <errno.h>
@@ -59,6 +61,7 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
        struct termios term, oterm;
        struct sigaction sa, saveint, savehup, savequit, saveterm;
        struct sigaction savetstp, savettin, savettou;
+       locale_t loc = __current_locale();
 
        /* I suppose we could alloc on demand in this case (XXX). */
        if (bufsiz == 0) {
@@ -115,11 +118,11 @@ restart:
                if (p < end) {
                        if ((flags & RPP_SEVENBIT))
                                ch &= 0x7f;
-                       if (isalpha(ch)) {
+                       if (isalpha_l(ch, loc)) {
                                if ((flags & RPP_FORCELOWER))
-                                       ch = tolower(ch);
+                                       ch = tolower_l(ch, loc);
                                if ((flags & RPP_FORCEUPPER))
-                                       ch = toupper(ch);
+                                       ch = toupper_l(ch, loc);
                        }
                        *p++ = ch;
                }
@@ -164,11 +167,20 @@ restart:
 char *
 getpass(const char *prompt)
 {
-       static char buf[_PASSWORD_LEN + 1];
+       const size_t bufsiz = _PASSWORD_LEN + 1;
+       static char *buf = NULL;
 
-       if (readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF) == NULL)
+       if (buf == NULL) {
+               buf = malloc(bufsiz);
+               if (buf == NULL) {
+                       return NULL;
+               }
+       }
+
+       if (readpassphrase(prompt, buf, bufsiz, RPP_ECHO_OFF) == NULL) {
                buf[0] = '\0';
-       return(buf);
+       }
+       return buf;
 }
 
 static void handler(int s)