This is more or less what regular getpass() does, but without turning off character echoing. You have to set HAVE_DEV_TTY to enable it. For now, only Linux enables this by default. People on other /dev/tty-enabled systems can submit patches to turn it on once they have tested it. Signed-off-by: Jeff King <peff@xxxxxxxx> --- Makefile | 8 ++++++++ compat/getpass.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/Makefile b/Makefile index d133e2b..a2afe31 100644 --- a/Makefile +++ b/Makefile @@ -227,6 +227,9 @@ all:: # # Define NO_REGEX if you have no or inferior regex support in your C library. # +# Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the +# user. +# # Define GETTEXT_POISON if you are debugging the choice of strings marked # for translation. In a GETTEXT_POISON build, you can turn all strings marked # for translation into gibberish by setting the GIT_GETTEXT_POISON variable @@ -835,6 +838,7 @@ ifeq ($(uname_S),Linux) NO_STRLCPY = YesPlease NO_MKSTEMPS = YesPlease HAVE_PATHS_H = YesPlease + HAVE_DEV_TTY = YesPlease endif ifeq ($(uname_S),GNU/kFreeBSD) NO_STRLCPY = YesPlease @@ -1641,6 +1645,10 @@ ifdef HAVE_PATHS_H BASIC_CFLAGS += -DHAVE_PATHS_H endif +ifdef HAVE_DEV_TTY + BASIC_CFLAGS += -DHAVE_DEV_TTY +endif + ifdef DIR_HAS_BSD_GROUP_SEMANTICS COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS endif diff --git a/compat/getpass.c b/compat/getpass.c index 8ae82f0..b5bd1dd 100644 --- a/compat/getpass.c +++ b/compat/getpass.c @@ -1,6 +1,41 @@ #include "../git-compat-util.h" +#ifdef HAVE_DEV_TTY + +char *getpass_echo(const char *prompt) +{ + static char buf[1024]; + FILE *fh; + int i; + + fh = fopen("/dev/tty", "w+"); + if (!fh) + return NULL; + + fputs(prompt, fh); + fflush(fh); + for (i = 0; i < sizeof(buf) - 1; i++) { + int ch = getc(fh); + if (ch == EOF || ch == '\n') + break; + buf[i] = ch; + } + buf[i] = '\0'; + + if (ferror(fh)) { + fclose(fh); + return NULL; + } + + fclose(fh); + return buf; +} + +#else + char *getpass_echo(const char *prompt) { return getpass(prompt); } + +#endif -- 1.7.7.4.7.g24824 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html