Bruno Haible wrote: >> 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?
STREQ_ retains the name and look while adding only one to the length. STREQ_opt is more descriptive, but longer >> 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? As Akim suggested, I think you'd want a different macro for that. This one really does intend to return ternary <, =, > 0, like strncmp. But I can improve the comment: >From fbca75fddb6918c0667783a7805847fc3bf78578 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@redhat.com> Date: Fri, 24 Feb 2012 10:02:18 +0100 Subject: [PATCH] doc: clarify a comment in system.h * src/system.h (STRNCMP_LIT): Clarify comment. Suggested by Bruno Haible. --- src/system.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system.h b/src/system.h index c4f262d..f312f88 100644 --- a/src/system.h +++ b/src/system.h @@ -186,7 +186,7 @@ select_plural (uintmax_t n) #define STRPREFIX(a, b) (strncmp(a, b, strlen (b)) == 0) /* Just like strncmp, but the second argument must be a literal string - and you don't specify the length. */ + and you don't specify the length; that comes from the literal. */ #define STRNCMP_LIT(s, literal) \ strncmp (s, "" literal "", sizeof (literal) - 1) -- 1.7.9.2.235.g1d0cd