bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: prohibit_strcmp


From: Bruno Haible
Subject: Re: prohibit_strcmp
Date: Thu, 23 Feb 2012 21:00:12 +0100
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

Hi Jim,

> That gnulib has two definitions is unfortunate, but I will not
> volunteer to change the STREQ that I've been using ;-)
> I don't see much value in streq.h, either, and hence, don't use it.

The value of streq.h is an optimized definition which is used in a few
places. I agree that your STREQ is more generally useful, especially to
avoid thinkos, therefore I wouldn't want to rename yours.

Akim suggests to rename STREQ in lib/streq.h; what name would you suggest?

> I use STRNCMP_LIT defined in coreutils/src/system.h:
> 
>     /* Just like strncmp, but the second argument must be a literal string
>        and you don't specify the length.  */
>     #define STRNCMP_LIT(s, literal) \
>       strncmp (s, "" literal "", sizeof (literal) - 1)

This comment is not clear enough. If someone writes
  STRNCMP_LIT (s, "foobar")
will it return true for s = "foobarbaz"? Will it return true for s = "foo"?

How about reformulating the comment?

  /* STRNCMP_LIT(S, PREFIX) returns true if the string S starts with the
     prefix string PREFIX.  PREFIX must be a literal string.  */

And given this specification, STRNCMP_LIT is an odd name. How about
STR_HAS_PREFIX or STR_STARTS_WITH?

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]