> I have this function in curl that looks like:
> int strequal(const char *first, const char *second)
> {
> #if defined(HAVE_STRCASECMP)
> return !strcasecmp(first, second);
> #elif defined(HAVE_STRCMPI)
> return !strcmpi(first, second);
> #elif defined(HAVE_STRICMP)
> return !stricmp(first, second);
> #else
> while (*first && *second) {
> if (toupper(*first) != toupper(*second)) {
> break;
> }
> first++;
> second++;
> }
> return toupper(*first) == toupper(*second);
> #endif
> }
> Now, this returns a non-compatible return code but as can be seen, that is
> easily fixed should we consider this a good thing...
Yeah. Just another point, and perhaps there are no libc.a's out there that do this any more, but I've run into systems (I believe IRIX but don't quote me) where you'd better do an isalpha() before you call toupper().
And using the words of the gnu libc.a, you need to return
(int)((unsigned char)*first) - (int)((unsigned char)*second);
Actually, I did it a quick and dirty way (ignoring the possibility that both strcasecmp and stricmp were missing):
#ifndef HAVE_STRCASECMP #define strcasecmp stricmp #endif
But now that I think of it, my instincts may have been right. Defining it as a macro gives us only one point of maintenance so that the next guy who comes along and wants to use a scrcasecmp() won't have to remember to put that in his code.
And just to add to the amusement, I've seen the function called strcmpi() somewhere.
-- Rev. Bob "Bob" Crispen crispen at hiwaay dot net "Good morning, doctors. I have taken the liberty of removing Windows 95 from my hard drive." -Arthur C. Clake, on what he imagines HAL's first words to beReceived on Wed 03 Jan 2001 02:18:22 AM GMT
This archive was generated by hypermail 2.3.0 : Sat 13 Mar 2010 03:46:12 AM GMT GMT