diff options
author | Lode Vandevenne <lode@google.com> | 2013-05-08 15:22:06 +0200 |
---|---|---|
committer | Lode Vandevenne <lode@google.com> | 2013-05-08 15:22:06 +0200 |
commit | c54dc204ef4278f949a965dc90e693799b6aae41 (patch) | |
tree | 419226b3fb126e93e1a1aa9dab8a7ac6d1789dca /src/zopflipng/zopflipng_bin.cc | |
parent | 337d27f25ef15a6cf34fef2acd0613fddc411cb1 (diff) | |
download | zopfli-c54dc204ef4278f949a965dc90e693799b6aae41.tar.gz |
remove usage of nonstandard getline
Diffstat (limited to 'src/zopflipng/zopflipng_bin.cc')
-rw-r--r-- | src/zopflipng/zopflipng_bin.cc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/zopflipng/zopflipng_bin.cc b/src/zopflipng/zopflipng_bin.cc index d264c07..3faea06 100644 --- a/src/zopflipng/zopflipng_bin.cc +++ b/src/zopflipng/zopflipng_bin.cc @@ -361,11 +361,14 @@ int main(int argc, char *argv[]) { } else { bool confirmed = true; if (!yes && !dryrun && already_exists) { - size_t nbytes = 2; - char* text = (char*) malloc(nbytes); printf("File %s exists, overwrite? (y/N) ", out_filename.c_str()); - int bytes_read = getline(&text, &nbytes, stdin); - confirmed = bytes_read > 0 && (text[0] == 'y' || text[0] == 'Y'); + char answer = 0; + // Read the first character, the others and enter with getchar. + while (int input = getchar()) { + if (input == '\n' || input == EOF) break; + else if (!answer) answer = input; + } + confirmed = answer == 'y' || answer == 'Y'; } if (confirmed) { if (!dryrun) { |