Mail Archives: cygwin-developers/1998/11/30/11:04:39
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
- Raw text -