libidav/utils.c

changeset 153
272173064319
parent 152
ff854d3df20c
child 158
33237261321e
--- a/libidav/utils.c	Thu Oct 08 12:58:49 2015 +0200
+++ b/libidav/utils.c	Thu Oct 08 14:25:53 2015 +0200
@@ -37,8 +37,12 @@
 #include <libxml/tree.h>
 #include <curl/curl.h>
 
-#ifndef _WIN32
+#ifdef _WIN32
+#include <conio.h>
+#define getpasswordchar() getch()
+#else
 #include <termios.h>
+#define getpasswordchar() getchar()
 #endif
 
 #include <openssl/sha.h>
@@ -447,10 +451,8 @@
     fprintf(stderr, "%s", prompt);
     fflush(stderr);
     
+#ifndef _WIN32
     // hide terminal input
-#ifdef _WIN32
-    // TODO
-#else
     struct termios oflags, nflags;
     tcgetattr(fileno(stdin), &oflags);
     nflags = oflags;
@@ -464,18 +466,17 @@
     // read password input
     UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND);
     int c = 0;
-    while((c = getchar()) != EOF) {
-        if(c == '\n') {
+    while((c = getpasswordchar()) != EOF) {
+        if(c == '\n' || c == '\r') {
             break;
         }
         ucx_buffer_putc(buf, c);
     }
     ucx_buffer_putc(buf, 0);
+    fflush(stdin);
     
+#ifndef _WIN32
     // restore terminal settings
-#ifdef _WIN32
-    // TODO
-#else
     if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) {
         perror("tcsetattr");
     }

mercurial