As mentioned in another answer, we need to use unsigned char with tolower():
int ci_strcmp(const unsigned char *s1, const unsigned char *s2)
{
for (;;) {
int c1 = tolower(*s1++);
int c2 = tolower(*s2++);
int result = (c1 > c2) - (c1 < c2);
if (result || !c1) return result;
}
}
/* Adapter for qsort */
int scmp(const void *p1, const void *p2)
{
const unsigned char *const *sp1 = p1;
const unsigned char *const *sp2 = p2;
return ci_strcmp(*sp1, *sp2);
}