Changeset View
Changeset View
Standalone View
Standalone View
stand/libsa/strcasecmp.c
Show All 33 Lines | |||||
#include <string.h> | #include <string.h> | ||||
#include "stand.h" | #include "stand.h" | ||||
#if defined(LIBC_SCCS) && !defined(lint) | #if defined(LIBC_SCCS) && !defined(lint) | ||||
static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; | static char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; | ||||
#endif /* LIBC_SCCS and not lint */ | #endif /* LIBC_SCCS and not lint */ | ||||
int | int | ||||
strcasecmp(s1, s2) | strcasecmp(const char *s1, const char *s2) | ||||
const char *s1, *s2; | |||||
{ | { | ||||
const u_char | const u_char *us1 = (const u_char *)s1, | ||||
*us1 = (const u_char *)s1, | |||||
*us2 = (const u_char *)s2; | *us2 = (const u_char *)s2; | ||||
while (tolower(*us1) == tolower(*us2++)) | u_char u1, u2; | ||||
if (*us1++ == '\0') | |||||
while ((u1 = tolower(*us1)) == (u2 = tolower(*us2))) { | |||||
if (u1 == '\0') { | |||||
return (0); | return (0); | ||||
return (tolower(*us1) - tolower(*--us2)); | |||||
} | } | ||||
us1++, us2++; | |||||
} | |||||
return (u1 - u2); | |||||
jrtc27: Given that tolower is an inline function I doubt this has any effect on the final code… | |||||
} | |||||
int | int | ||||
strncasecmp(s1, s2, n) | strncasecmp(const char *s1, const char *s2, size_t n) | ||||
const char *s1, *s2; | |||||
size_t n; | |||||
{ | { | ||||
if (n != 0) { | if (n != 0) { | ||||
const u_char | const u_char *us1 = (const u_char *)s1, | ||||
*us1 = (const u_char *)s1, | |||||
*us2 = (const u_char *)s2; | *us2 = (const u_char *)s2; | ||||
u_char u1, u2; | |||||
do { | do { | ||||
if (tolower(*us1) != tolower(*us2++)) | if ((u1 = tolower(*us1)) != (u2 = tolower(*us2))) { | ||||
return (tolower(*us1) - tolower(*--us2)); | return (u1 - u2); | ||||
if (*us1++ == '\0') | } | ||||
if (u1 == '\0') { | |||||
break; | break; | ||||
} | |||||
us1++, us2++; | |||||
} while (--n != 0); | } while (--n != 0); | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } |
Given that tolower is an inline function I doubt this has any effect on the final code generated, these are all simple transformations for half-decent compilers to make.