diff options
author | Chen Gang | 2014-07-06 10:43:33 +0200 |
---|---|---|
committer | Michael Tokarev | 2014-08-08 22:06:32 +0200 |
commit | fdcf6e65bce1f8972030fed7af5e8aa5f6ae92c6 (patch) | |
tree | 2a427119adb314059ea7447bd201d92411608286 /qemu-img.c | |
parent | hw/timer: Move extern declaration from .c to .h file (diff) | |
download | qemu-fdcf6e65bce1f8972030fed7af5e8aa5f6ae92c6.tar.gz qemu-fdcf6e65bce1f8972030fed7af5e8aa5f6ae92c6.tar.xz qemu-fdcf6e65bce1f8972030fed7af5e8aa5f6ae92c6.zip |
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>
Diffstat (limited to 'qemu-img.c')
-rw-r--r-- | qemu-img.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/qemu-img.c b/qemu-img.c index d4518e724f..19495bb594 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -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) { int c, i; + printf("Password: "); fflush(stdout); i = 0; for(;;) { c = getchar(); - if (c == '\n') + if (c < 0) { + buf[i] = '\0'; + return -1; + } else if (c == '\n') { break; - if (i < (buf_size - 1)) + } else if (i < (buf_size - 1)) { buf[i++] = c; + } } buf[i] = '\0'; return 0; |