[PATCH:xev 2/2] Use strncasecmp if available, instead of a tolower loop & strncmp

Peter Hutterer peter.hutterer at who-t.net
Tue Jan 15 16:31:06 PST 2013


On Tue, Jan 15, 2013 at 04:07:58PM -0800, Alan Coopersmith wrote:
> On 01/15/13 03:51 PM, Peter Hutterer wrote:
> >> +#ifndef HAVE_STRNCASECMP
> >>      char *cp;
> >>  
> >>      for (cp = s; *cp; cp++) {
> >>  	if (isascii (*cp) && isupper (*cp))
> >>  	    *cp = tolower (*cp);
> >>      }
> >> +#define strncasecmp strncmp
> >> +#endif
> >>  
> >> -    if (strncmp (s, "notuseful", len) == 0) return (NotUseful);
> >> -    if (strncmp (s, "whenmapped", len) == 0) return (WhenMapped);
> >> -    if (strncmp (s, "always", len) == 0) return (Always);
> >> +    if (strncasecmp (s, "notuseful", len) == 0) return (NotUseful);
> >> +    if (strncasecmp (s, "whenmapped", len) == 0) return (WhenMapped);
> >> +    if (strncasecmp (s, "always", len) == 0) return (Always);
> > 
> > which systems do we support that don't have strncasecmp?
> 
> Good question - I remembered other Xorg configure scripts checking for it, but
> I don't know why, and checking the Unix98 spec it was included there:
> http://pubs.opengroup.org/onlinepubs/007908799/xsh/strcasecmp.html
> 
> so it should be in our supported baseline.   Anyone know of any reason we can't
> just assume strncasecmp and drop the #ifndef case above?
> 
> > the man page suggests uppercase spelling "-bs {NotUseful,WhenMapped,Always}"
> > so this could break on those systems. maybe change the above to match the
> > spelling in the man page?
> 
> How would it break?  They'd use the old code that does tolower on the input
> before comparison - if we require strncasecmp and drop support for them, then
> we could uppercase with impunity.

oh, sorry, misread. I thought that the tolower hunk was removed. I need to
sleep more.

Cheers,
   Peter


More information about the xorg-devel mailing list