qemu-img: Check getchar() return value in read_password() for WIN32

getchar() is a standard c library function which may return with failure
(e.g. -1), so like another platforms, also need check it under WIN32.

And make the related code match current qemu code styles, too.

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
Chen Gang 2014-07-06 16:43:33 +08:00 committed by Michael Tokarev
parent f13bef9592
commit fdcf6e65bc

View File

@ -185,15 +185,20 @@ static int GCC_FMT_ATTR(2, 3) qprintf(bool quiet, const char *fmt, ...)
static int read_password(char *buf, int buf_size) static int read_password(char *buf, int buf_size)
{ {
int c, i; int c, i;
printf("Password: "); printf("Password: ");
fflush(stdout); fflush(stdout);
i = 0; i = 0;
for(;;) { for(;;) {
c = getchar(); c = getchar();
if (c == '\n') if (c < 0) {
buf[i] = '\0';
return -1;
} else if (c == '\n') {
break; break;
if (i < (buf_size - 1)) } else if (i < (buf_size - 1)) {
buf[i++] = c; buf[i++] = c;
}
} }
buf[i] = '\0'; buf[i] = '\0';
return 0; return 0;