Message ID | 20131218185058.GR2609@titan.lakedaemon.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
diff --git a/string.c b/string.c index 5105490143c8..629c281f3abd 100644 --- a/string.c +++ b/string.c @@ -18,14 +18,18 @@ int strlen(const char *str) int strncmp(const char *stra, const char *strb, int len) { - int diff=0; - const char *a = stra; - const char *b = strb; - - while ((a - stra) < len) - diff += *a++ - *b++; - - return diff; + unsigned char c1, c2; + + while (len) { + c1 = *stra++; + c2 = *strb++; + if (c1 != c2) + return c1 < c2 ? -1 : 1; + if (!c1) + break; + len--; + } + return 0; } void *gethexaddr(const char *str, const char **end)