2 * Copyright 2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, axeld@pinc-software.de
18 getpass(const char *prompt
)
20 static char password
[128];
21 struct termios termios
;
26 if (tcgetattr(fileno(stdin
), &termios
) == 0) {
27 struct termios noEchoTermios
= termios
;
29 noEchoTermios
.c_lflag
&= ~(ECHO
| ISIG
);
30 changed
= tcsetattr(fileno(stdin
), TCSAFLUSH
, &noEchoTermios
) == 0;
34 fputs(prompt
, stdout
);
38 if (fgets(password
, sizeof(password
), stdin
) != NULL
) {
39 size_t length
= strlen(password
);
41 if (password
[length
- 1] == '\n')
42 password
[length
- 1] = '\0';
45 // Manually move to the next line
50 // Restore termios setting
52 tcsetattr(fileno(stdin
), TCSAFLUSH
, &termios
);