]> git.buserror.net Git - polintos/scott/priv.git/blobdiff - lib/c/freestanding/string.c
Random stuff.
[polintos/scott/priv.git] / lib / c / freestanding / string.c
index 0241f91b5c10176ef2fb8f54fc3b179e16717699..77c13ef698b79e970cc9b131522b9afa50e9d01a 100644 (file)
@@ -51,8 +51,6 @@ int memcmp(const void *b1, const void *b2, size_t len)
        for (pos = 0; pos < len; pos++) {
                if (c1[pos] != c2[pos])
                        return c1[pos] - c2[pos];
-                       
-               pos++;
        }
        
        return 0;
@@ -152,12 +150,12 @@ int strcmp(const char *s1, const char *s2)
                s2++;
        }
 
-       return *s2 - *s1;
+       return (unsigned char)*s2 - (unsigned char)*s1;
 }
 
-int strncmp(const char *s1, const char *s2, int n)
+int strncmp(const char *s1, const char *s2, size_t n)
 {
-       int i = 0;
+       size_t i = 0;
 
        while (i < n && s1[i] && s2[i] && s1[i] == s2[i])
                i++;
@@ -165,7 +163,7 @@ int strncmp(const char *s1, const char *s2, int n)
        if (i == n)
                return 0;
 
-       return *s2 - *s1;
+       return (unsigned char)s2[i] - (unsigned char)s1[i];
 }
 
 char *strchr(const char *s, int c)