From 4f7da73885934a052425fc71861b0c9922c2122f Mon Sep 17 00:00:00 2001 From: Mats Date: Tue, 11 Mar 2014 20:15:36 +0100 Subject: Unify use of string comparisons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * strncmp(s1, s2, strlen(s2)) → BEGINS_WITH(s1, s2) * strncmp(s1, s2, strlen(s1)) → strcmp(s1, s2) * Prefer case-insensitive comparison for options --- src/print_eth_info.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/print_eth_info.c') diff --git a/src/print_eth_info.c b/src/print_eth_info.c index 45a44a4..c446da4 100644 --- a/src/print_eth_info.c +++ b/src/print_eth_info.c @@ -90,8 +90,8 @@ static int print_eth_speed(char *outwalk, const char *interface) { * Skip these non-informative values and go right ahead to the * actual speeds. */ - if (strncmp(desc->ifmt_string, "autoselect", strlen("autoselect")) == 0 || - strncmp(desc->ifmt_string, "auto", strlen("auto")) == 0) + if (BEGINS_WITH(desc->ifmt_string, "autoselect") || + BEGINS_WITH(desc->ifmt_string, "auto")) continue; if (IFM_TYPE_MATCH(desc->ifmt_word, ifmr.ifm_active) && @@ -131,10 +131,10 @@ void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, cons continue; } - if (strncmp(walk+1, "ip", strlen("ip")) == 0) { + if (BEGINS_WITH(walk+1, "ip")) { outwalk += sprintf(outwalk, "%s", ip_address); walk += strlen("ip"); - } else if (strncmp(walk+1, "speed", strlen("speed")) == 0) { + } else if (BEGINS_WITH(walk+1, "speed")) { outwalk += print_eth_speed(outwalk, interface); walk += strlen("speed"); } -- cgit v1.2.3