From c34b69b5c7aa86fe76f90577195d13bbcf300658 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 23 Dec 2011 14:47:30 -0600 Subject: 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 --- src/pacman/conf.c | 3 +-- src/pacman/util.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3-24-g4f1b