Index: branches/chucko/i386/libsa/string.c =================================================================== --- branches/chucko/i386/libsa/string.c (revision 2332) +++ branches/chucko/i386/libsa/string.c (revision 2333) @@ -110,9 +110,9 @@ size_t strlen(const char * s) { - int n = 0; - while (*s++) n++; - return(n); + const char* save = s; + while (*s++); + return (--s) - save; } /*#endif*/ @@ -138,13 +138,19 @@ return (*s1 - *s2); } -int strncmp(const char * s1, const char * s2, size_t len) +/* Derived from FreeBSD source */ +int strncmp(const char * s1, const char * s2, size_t n) { - register int n = len; - while (--n >= 0 && *s1 == *s2++) - if (*s1++ == '\0') - return(0); - return(n<0 ? 0 : *s1 - *--s2); + if (!n) + return 0; + do { + if (*s1 != *s2++) + return (*(const unsigned char *)s1 - + *(const unsigned char *)(s2 - 1)); + if (!*s1++) + break; + } while (--n); + return 0; } char * @@ -161,8 +167,7 @@ { register char *ret = s1; while (n && (*s1++ = *s2++)) - --n; - /* while (n--) *s1++ = '\0'; */ + --n; if (n > 0) { bzero(s1, n); } @@ -224,15 +229,17 @@ register char *ret = s1; while (*s1) s1++; - while (n-- && *s2) - *s1++ = *s2++; - *s1 = '\0'; + while (n-- && (*s1++ = *s2++)); return ret; } char *strcat(char *s1, const char *s2) { - return(strncat(s1, s2, strlen(s2))); + register char *ret = s1; + while (*s1) + s1++; + while ((*s1++ = *s2++)); + return ret; } char *strdup(const char *s1)