strcasecmp and strncasecmp
I am doomed to work on old machines, which never have strcasecmp or strncasecmp. Each time I re-implement them, as I never remember where I last put them in. No more:
/* YR 19APR 2007 -- use at own risk */
int strncasecmp(const char *s1, const char *s2, size_t n)
{
int c1, c2;
while (n--) {
c1 = toupper(*s1++);
c2 = toupper(*s2++);
if ((!c1 || !c2) || (c1 != c2))
return c1 - c2;
}
return 0;
}
/* YR 19APR 2007 -- use at own risk */
int strcasecmp(const char *s1, const char *s2)
{
int c1, c2;
while (1) {
c1 = toupper(*s1++);
c2 = toupper(*s2++);
if ((!c1 || !c2) || (c1 != c2))
return c1 - c2;
}
}