projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix getopt handling of ':' modifier for multibyte option characters
[musl]
/
src
/
legacy
/
getpass.c
diff --git
a/src/legacy/getpass.c
b/src/legacy/getpass.c
index
d439a2a
..
15ab985
100644
(file)
--- a/
src/legacy/getpass.c
+++ b/
src/legacy/getpass.c
@@
-1,8
+1,9
@@
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdio.h>
-#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
+#include <string.h>
char *getpass(const char *prompt)
{
char *getpass(const char *prompt)
{
@@
-11,7
+12,7
@@
char *getpass(const char *prompt)
ssize_t l;
static char password[128];
ssize_t l;
static char password[128];
- if ((fd = open("/dev/tty", O_RD
ONLY|O_NOCTTY)) < 0) fd =
0;
+ if ((fd = open("/dev/tty", O_RD
WR|O_NOCTTY|O_CLOEXEC)) < 0) return
0;
tcgetattr(fd, &t);
s = t;
tcgetattr(fd, &t);
s = t;
@@
-22,8
+23,7
@@
char *getpass(const char *prompt)
tcsetattr(fd, TCSAFLUSH, &t);
tcdrain(fd);
tcsetattr(fd, TCSAFLUSH, &t);
tcdrain(fd);
- fputs(prompt, stderr);
- fflush(stderr);
+ dprintf(fd, "%s", prompt);
l = read(fd, password, sizeof password);
if (l >= 0) {
l = read(fd, password, sizeof password);
if (l >= 0) {
@@
-33,7
+33,8
@@
char *getpass(const char *prompt)
tcsetattr(fd, TCSAFLUSH, &s);
tcsetattr(fd, TCSAFLUSH, &s);
- if (fd > 2) close(fd);
+ dprintf(fd, "\n");
+ close(fd);
- return password;
+ return
l<0 ? 0 :
password;
}
}