diff options
author | Dan McGee <dan@archlinux.org> | 2011-12-23 14:47:30 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-12-23 14:47:30 -0600 |
commit | c34b69b5c7aa86fe76f90577195d13bbcf300658 (patch) | |
tree | 271af389aea6956a92c460f8424b5d629011a025 /src | |
parent | 38143770a9a1b4b88503fc7b1b9098a5957e0f4e (diff) |
Convert strtrim/strlen paired calls to only strtrim
This utilizes the new return value so we don't have to find the length
of the string again.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/conf.c | 3 | ||||
-rw-r--r-- | src/pacman/util.c | 18 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 117aecd4..7ba2791c 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -726,8 +726,7 @@ static int _parseconfig(const char *file, struct section_t *section, *ptr = '\0'; } - strtrim(line); - line_len = strlen(line); + line_len = strtrim(line); if(line_len == 0) { continue; diff --git a/src/pacman/util.c b/src/pacman/util.c index 4160c44d..467bedfe 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1228,14 +1228,14 @@ static int multiselect_parse(char *array, int count, char *response) for(str = response; ; str = NULL) { int include = 1; int start, end; + size_t len; char *ends = NULL; char *starts = strtok_r(str, " ", &saveptr); if(starts == NULL) { break; } - strtrim(starts); - int len = strlen(starts); + len = strtrim(starts); if(len == 0) continue; @@ -1314,6 +1314,7 @@ int multiselect_question(char *array, int count) if(fgets(response, response_len, stdin)) { const size_t response_incr = 64; + size_t len; /* handle buffer not being large enough to read full line case */ while(*lastchar == '\0' && lastchar[-1] != '\n') { response_len += response_incr; @@ -1330,8 +1331,9 @@ int multiselect_question(char *array, int count) return -1; } } - strtrim(response); - if(strlen(response) > 0) { + + len = strtrim(response); + if(len > 0) { if(multiselect_parse(array, count, response) == -1) { /* only loop if user gave an invalid answer */ continue; @@ -1374,8 +1376,8 @@ int select_question(int count) flush_term_input(); if(fgets(response, sizeof(response), stdin)) { - strtrim(response); - if(strlen(response) > 0) { + size_t len = strtrim(response); + if(len > 0) { int n; if(parseindex(response, &n, 1, count) != 0) continue; @@ -1423,8 +1425,8 @@ static int question(short preset, char *fmt, va_list args) flush_term_input(); if(fgets(response, sizeof(response), stdin)) { - strtrim(response); - if(strlen(response) == 0) { + size_t len = strtrim(response); + if(len == 0) { return preset; } |