Re[4]: [hypermail] Wanted: a good flag for Win32 and an m4 guru

From: Rev. Bob 'Bob' Crispen <crispen_at_hiwaay.net_at_hypermail-project.org>
Date: Tue, 2 Jan 2001 18:16:01 -0600
Message-ID: <5575540269.20010102181601_at_hiwaay.net>


The voices are telling me that Hypermail said on Tuesday, January 02, 2001:

> 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 be
Received 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