X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=payloads%2Flibpayload%2Flibc%2Fstring.c;h=8c6ea99115d3dcef0286656e751bb8f3c7927b13;hb=c3c827cf864b10d5086177602f0157b9596bc380;hp=7bf19ace375bceaf545c1f7f87fb085d8c88ee26;hpb=154931c66fcc70424a10f3c99f63e361538cd888;p=coreboot.git diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c index 7bf19ace3..8c6ea9911 100644 --- a/payloads/libpayload/libc/string.c +++ b/payloads/libpayload/libc/string.c @@ -89,14 +89,15 @@ size_t strlen(const char *str) */ int strcasecmp(const char *s1, const char *s2) { - int i; + int i, res; - for (i = 0; s1[i] != '\0'; i++) { - if (tolower(s1[i]) != tolower(s2[i])) - return s1[i] - s2[i]; + for (i = 0; 1; i++) { + res = tolower(s1[i]) - tolower(s2[i]); + if (res || (s1[i] == '\0')) + break; } - return 0; + return res; } /** @@ -109,14 +110,16 @@ int strcasecmp(const char *s1, const char *s2) */ int strncasecmp(const char *s1, const char *s2, size_t maxlen) { - int i; + int i, res; + res = 0; for (i = 0; i < maxlen; i++) { - if (tolower(s1[i]) != tolower(s2[i])) - return s1[i] - s2[i]; + res = tolower(s1[i]) - tolower(s2[i]); + if (res || (s1[i] == '\0')) + break; } - return s1[i] - s2[i]; + return res; } /** @@ -130,14 +133,15 @@ int strncasecmp(const char *s1, const char *s2, size_t maxlen) */ int strcmp(const char *s1, const char *s2) { - int i; + int i, res; - for (i = 0; s1[i] != '\0'; i++) { - if (s1[i] != s2[i]) - return s1[i] - s2[i]; + for (i = 0; 1; i++) { + res = s1[i] - s2[i]; + if (res || (s1[i] == '\0')) + break; } - return s1[i] - s2[i]; + return res; } /** @@ -150,14 +154,16 @@ int strcmp(const char *s1, const char *s2) */ int strncmp(const char *s1, const char *s2, size_t maxlen) { - int i; + int i, res; + res = 0; for (i = 0; i < maxlen; i++) { - if (s1[i] != s2[i]) - return s1[i] - s2[i]; + res = s1[i] - s2[i]; + if (res || (s1[i] == '\0')) + break; } - return 0; + return res; } /** @@ -240,7 +246,7 @@ char *strncat(char *d, const char *s, size_t n) * * @param d The destination string. * @param s The source string. - * @param n Not more than n characters from s will be appended to d. + * @param n d will have at most n-1 characters (plus NUL) after invocation. * @return A pointer to the destination string. */ size_t strlcat(char *d, const char *s, size_t n) @@ -401,7 +407,7 @@ static int _offset(char ch, int base) if (ch >= '0' && ch <= '9') return ch - '0'; else - return tolower(ch) - 'a'; + return 10 + tolower(ch) - 'a'; } /** @@ -467,6 +473,11 @@ long int strtol(const char *ptr, char **endptr, int base) return ret * negative; } +long atol(const char *nptr) +{ + return strtol(nptr, NULL, 10); +} + /** * Convert the initial portion of a string into an unsigned int * @param ptr A pointer to the string to convert