one loop only
From 778095c3f3fd24b2c5ad1112e4df5cd20250c61e Mon Sep 17 00:00:00 2001 From: Rodgger Bruno <rodggerbr...@gmail.com> Date: Sun, 22 Oct 2017 15:35:32 -0300 Subject: [PATCH] only strlen in loop
Signed-off-by: Rodgger Bruno <rodggerbr...@gmail.com> --- src/ftp-ls.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ftp-ls.c b/src/ftp-ls.c index 27addd45..93d3a637 100644 --- a/src/ftp-ls.c +++ b/src/ftp-ls.c @@ -682,7 +682,7 @@ static struct fileinfo * ftp_parse_vms_ls (const char *file) { FILE *fp; - int dt, i, j, len; + int dt, i, j, tok_len; int perms; size_t bufsize = 0; time_t timenow; @@ -776,17 +776,17 @@ ftp_parse_vms_ls (const char *file) ".DIR;1" file type and version number, as the plain name is what will work in a CWD command. */ - len = strlen (tok); - if (!c_strncasecmp((tok + (len - 4)), ".DIR", 4)) + tok_len = strlen (tok); + if (!c_strncasecmp((tok + (tok_len - 4)), ".DIR", 4)) { - *(tok+ (len - 4)) = '\0'; /* Discard ".DIR". */ + *(tok+ (tok_len - 4)) = '\0'; /* Discard ".DIR". */ cur.type = FT_DIRECTORY; cur.perms = VMS_DEFAULT_PROT_DIR; DEBUGP (("Directory (nv)\n")); } - else if (!c_strncasecmp ((tok + (len - 6)), ".DIR;1", 6)) + else if (!c_strncasecmp ((tok + (tok_len - 6)), ".DIR;1", 6)) { - *(tok+ (len - 6)) = '\0'; /* Discard ".DIR;1". */ + *(tok+ (tok_len - 6)) = '\0'; /* Discard ".DIR;1". */ cur.type = FT_DIRECTORY; cur.perms = VMS_DEFAULT_PROT_DIR; DEBUGP (("Directory (v)\n")); @@ -871,14 +871,16 @@ ftp_parse_vms_ls (const char *file) { DEBUGP (("Token: >%s<: ", tok)); - if ((strlen (tok) < 12) && (strchr( tok, '-') != NULL)) + tok_len = (int) strlen (tok); + + if (tok_len < 12) && (strchr( tok, '-') != NULL)) { /* Date. */ DEBUGP (("Date.\n")); strcpy( date_str, tok); strcat( date_str, " "); } - else if ((strlen (tok) < 12) && (strchr( tok, ':') != NULL)) + else if (tok_len < 12) && (strchr( tok, ':') != NULL)) { /* Time. */ DEBUGP (("Time. ")); @@ -898,7 +900,7 @@ ftp_parse_vms_ls (const char *file) perms = 0; j = 0; /*FIXME: Should not be using the variable like this. */ - for (i = 0; i < (int) strlen(tok); i++) + for (i = 0; i < tok_len; i++) { switch (tok[ i]) { -- 2.11.0