From: cgf AT cygnus DOT com (Christopher Faylor) Subject: strcasecmp revisited 30 Nov 1998 11:04:39 -0800 Message-ID: <19981130132257.B15656.cygnus.cygwin32.developers@cygnus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: cygwin32-developers AT cygnus DOT com Someone on the gnu-win32 mailing list noted that strcasecmp does not return "the right thing" when comparing "a" to "_". Instead of returning the difference between "_" and "a", it returns the difference between "_" and "A". I was just about to check in a fix for this behavior when it occurred to me that I should check the Single UNIX Specification to see how they say this should be handled. Here's what they say: The strcasecmp() function compares, while ignoring differences in case, the string pointed to by s1 to the string pointed to by s2. The strncasecmp() function compares, while ignoring differences in case, not more than n bytes from the string pointed to by s1 to the string pointed to by s2. In the POSIX locale, strcasecmp() and strncasecmp() do upper to lower conversions, then a byte comparison. The results are unspecified in other locales. The newlib strcasecmp does a toupper on the string and ignores locales but, except for that, it seems to be complying with the spirit of the above paragraphs. My change detected the case where a non-alpha was being compared to an alpha and avoided doing a toupper in that case. I'm wondering if this is the correct thing to do given the above description? Does anybody have any opinions? cgf