libpayload: Fix documentation
[coreboot.git] / payloads / libpayload / libc / string.c
index 1ca8bc12e828e7eab4c1d090837d045ce383fd11..2e0a558b20c3a89d2f134ca40f67d74183bc6826 100644 (file)
@@ -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; 1; 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 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 0;
+       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; 1; 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;
 }
 
 /**
@@ -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';
 }
 
 /**