unzip: add missing fflush; code shrink

function                                             old     new   delta
my_fgets80                                             -      41     +41
unzip_main                                          2291    2242     -49

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2013-01-22 11:16:08 +01:00
parent 9b7ebfe644
commit bf99807657

View File

@ -267,6 +267,14 @@ static void unzip_extract(zip_header_t *zip_header, int dst_fd)
} }
} }
static void my_fgets80(char *buf80)
{
fflush_all();
if (!fgets(buf80, 80, stdin)) {
bb_perror_msg_and_die("can't read standard input");
}
}
int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unzip_main(int argc, char **argv) int unzip_main(int argc, char **argv)
{ {
@ -291,7 +299,7 @@ int unzip_main(int argc, char **argv)
llist_t *zreject = NULL; llist_t *zreject = NULL;
char *base_dir = NULL; char *base_dir = NULL;
int i, opt; int i, opt;
char key_buf[80]; char key_buf[80]; /* must match size used by my_fgets80 */
struct stat stat_buf; struct stat stat_buf;
/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP: /* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP:
@ -624,10 +632,7 @@ int unzip_main(int argc, char **argv)
i = 'y'; i = 'y';
} else { } else {
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn); printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
fflush_all(); my_fgets80(key_buf);
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
bb_perror_msg_and_die("can't read standard input");
}
i = key_buf[0]; i = key_buf[0];
} }
} else { /* File is not regular file */ } else { /* File is not regular file */
@ -668,9 +673,7 @@ int unzip_main(int argc, char **argv)
case 'r': case 'r':
/* Prompt for new name */ /* Prompt for new name */
printf("new name: "); printf("new name: ");
if (!fgets(key_buf, sizeof(key_buf), stdin)) { my_fgets80(key_buf);
bb_perror_msg_and_die("can't read standard input");
}
free(dst_fn); free(dst_fn);
dst_fn = xstrdup(key_buf); dst_fn = xstrdup(key_buf);
chomp(dst_fn); chomp(dst_fn);