Short answer: since strcasecmp() not in the C standard, this makes it non-standard.
strcasecmp() defined in popular standards such as 4.4BSD, POSIX.1-2001.
Defining functions without taking errors into account opens the door to parts that are not needed. They often include the result + or - without random comparisons, and not just the 0 or non-0 used by the OP. In particular:
In the POSIX locale, strcasecmp () and strncasecmp () should behave as if the strings were converted to lowercase and then the bytes were compared. Results are not defined in other locales.
The problem with this is with lowercase and lowercase letters that do not have a mapping from 1 to 1. Consider a local one that has E , E and é , but not É , but toupper('é') → 'E' . Then, “if the lines were converted to lowercase”, 'E' has 2 options.
As a portable solution, think of round trips as the letter (upper and lower) to deal with the comparisons not one to one:
int SGA_stricmp(const char *a, const char *b) { int ca, cb; do { ca = (unsigned char) *a++; cb = (unsigned char) *b++; ca = tolower(toupper(ca)); cb = tolower(toupper(cb)); } while (ca == cb && ca != '\0'); return ca - cb; }
If you do not want to round values, use:
ca = tolower(ca); cb = tolower(cb);
In detail: toupper() and tolower() defined only for int in the range from unsigned char and EOF .
source share