# Similar to the gnulib maint.mk rule for sc_prohibit_strcmp
# Use STREQ_LEN or STRPREFIX rather than comparing strncmp == 0, or != 0.
sc_prohibit_strncmp:
- @grep -nE '! *str''ncmp *\(|\<str''ncmp *\(.+\) *[!=]=' \
- $$($(VC_LIST_EXCEPT)) \
- | grep -vE ':# *define STR(N?EQ_LEN|PREFIX)\(' && \
- { echo '$(ME): use STREQ_LEN or STRPREFIX instead of str''ncmp' \
- 1>&2; exit 1; } || :
+ @prohibit='^[^#].*str''ncmp *\(' \
+ halt='use STREQ_LEN or STRPREFIX instead of str''ncmp' \
+ $(_sc_search_regexp)
# Enforce recommended preprocessor indentation style.
sc_preprocessor_indentation:
{
/* Ignore "posix-" prefix, for compatibility with ls. */
static char const posix_prefix[] = "posix-";
- while (strncmp (time_style, posix_prefix, sizeof posix_prefix - 1)
- == 0)
- time_style += sizeof posix_prefix - 1;
+ static const size_t prefix_len = sizeof posix_prefix - 1;
+ while (STREQ_LEN (time_style, posix_prefix, prefix_len))
+ time_style += prefix_len;
}
}
int i;
for (i = 0; i < argc_names; i++)
- if (strncmp (UT_USER (utmp_buf), argv_names[i], UT_USER_SIZE)
- == 0)
+ if (STREQ_LEN (UT_USER (utmp_buf), argv_names[i], UT_USER_SIZE))
{
print_entry (utmp_buf);
break;
#define STREQ(a, b) (strcmp (a, b) == 0)
#define STREQ_LEN(a, b, n) (strncmp (a, b, n) == 0)
-#define STRPREFIX(a, b) (strncmp(a, b, strlen (b)) == 0)
+#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; that comes from the literal. */
-#define STRNCMP_LIT(s, literal) \
- strncmp (s, "" literal "", sizeof (literal) - 1)
+#define STRNCMP_LIT(s, lit) strncmp (s, "" lit "", sizeof (lit) - 1)
#if !HAVE_DECL_GETLOGIN
char *getlogin ();
{
/* 'match_length' is constant for non-regexp boundaries. */
while (*--match_start != first_char
- || (match_length1 && strncmp (match_start + 1, separator1,
- match_length1)))
+ || (match_length1 && !STREQ_LEN (match_start + 1, separator1,
+ match_length1)))
/* Do nothing. */ ;
}
while (n--)
{
if (!my_line_only
- || strncmp (ttyname_b, utmp_buf->ut_line,
- sizeof (utmp_buf->ut_line)) == 0)
+ || STREQ_LEN (ttyname_b, utmp_buf->ut_line,
+ sizeof (utmp_buf->ut_line)))
{
if (need_users && IS_USER_PROCESS (utmp_buf))
print_user (utmp_buf, boottime);