diff options
author | Dan McGee <dan@archlinux.org> | 2011-08-08 17:05:25 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-08-08 17:05:25 -0500 |
commit | 8fa330335f9eb465724ed778464502f844e930ae (patch) | |
tree | 2161500fbdc1ca52f0e1bf15c9f0ab90737d5d01 /src/pacman/util.c | |
parent | ef4757afa5d31ff6a6c09e3410c889f152826f4f (diff) | |
parent | 67445334e71eaf6138561eee8e5561733a59fc69 (diff) |
Merge branch 'maint'
Conflicts:
lib/libalpm/dload.c
lib/libalpm/po/fi.po
lib/libalpm/po/libalpm.pot
po/de.po
po/fi.po
src/pacman/po/pacman.pot
src/pacman/util.c
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r-- | src/pacman/util.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c index 8765da7f..e8c0a299 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1134,8 +1134,9 @@ static int multiselect_parse(char *array, int count, char *response) int multiselect_question(char *array, int count) { - char response[64]; + char *response, *lastchar; FILE *stream; + size_t response_len = 64; if(config->noconfirm) { stream = stdout; @@ -1144,12 +1145,21 @@ int multiselect_question(char *array, int count) stream = stderr; } + response = malloc(response_len); + if(!response) { + return -1; + } + lastchar = response + response_len - 1; + /* sentinel byte to later see if we filled up the entire string */ + *lastchar = 1; + while(1) { memset(array, 1, count); fprintf(stream, "\n"); fprintf(stream, _("Enter a selection (default=all)")); fprintf(stream, ": "); + fflush(stream); if(config->noconfirm) { fprintf(stream, "\n"); @@ -1158,7 +1168,24 @@ int multiselect_question(char *array, int count) flush_term_input(); - if(fgets(response, sizeof(response), stdin)) { + if(fgets(response, response_len, stdin)) { + const size_t response_incr = 64; + /* handle buffer not being large enough to read full line case */ + while(*lastchar == '\0' && lastchar[-1] != '\n') { + response_len += response_incr; + response = realloc(response, response_len); + if(!response) { + return -1; + } + lastchar = response + response_len - 1; + /* sentinel byte */ + *lastchar = 1; + if(fgets(response + response_len - response_incr - 1, + response_incr + 1, stdin) == 0) { + free(response); + return -1; + } + } strtrim(response); if(strlen(response) > 0) { if(multiselect_parse(array, count, response) == -1) { @@ -1166,9 +1193,14 @@ int multiselect_question(char *array, int count) continue; } } + break; + } else { + free(response); + return -1; } - break; } + + free(response); return 0; } |