summaryrefslogtreecommitdiff
path: root/src/system.h
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-03-31 17:59:16 +0200
committerJim Meyering <meyering@redhat.com>2011-04-03 21:55:27 +0200
commit03583f8d646f4cc4d5f91b7ed763c147a00e2f44 (patch)
treee75e865b606e1fd762b53fa0d1240f619a4338a4 /src/system.h
parent1c3654cb1fb0d8f3c422c766028d0783a40f4a42 (diff)
downloadcoreutils-03583f8d646f4cc4d5f91b7ed763c147a00e2f44.tar.xz
maint: prohibit direct use of strncmp: prefer STREQ_LEN, STRNCMP_LIT
* cfg.mk (sc_prohibit_strncmp): New rule, mostly from libvirt. * src/system.h (STREQ_LEN, STRPREFIX, STRNCMP_LIT): Define. * src/df.c (get_dev, get_point): Convert. * src/extent-scan.c (extent_need_sync): Likewise. * src/ls.c (is_colored, decode_switches): Likewise. (parse_ls_color, (print_color_indicator): Likewise. * src/md5sum.c (split_3): Likewise. * src/split.c (main, emit_ancillary_info): Likewise. * src/tr.c (look_up_char_class): Likewise. * src/uname.c (main): Likewise. * src/who.c (scan_entries): Likewise.
Diffstat (limited to 'src/system.h')
-rw-r--r--src/system.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/system.h b/src/system.h
index b86e57047..1c351bd1b 100644
--- a/src/system.h
+++ b/src/system.h
@@ -257,6 +257,13 @@ select_plural (uintmax_t n)
}
#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)
+
+/* Just like strncmp, but the first argument must be a literal string
+ and you don't specify the length. */
+#define STRNCMP_LIT(s, literal) \
+ strncmp (s, "" literal "", sizeof (literal) - 1)
#if !HAVE_DECL_GETLOGIN
char *getlogin ();
@@ -607,7 +614,7 @@ emit_ancillary_info (void)
/* Don't output this redundant message for English locales.
Note we still output for 'C' so that it gets included in the man page. */
const char *lc_messages = setlocale (LC_MESSAGES, NULL);
- if (lc_messages && strncmp (lc_messages, "en_", 3))
+ if (lc_messages && STRNCMP_LIT (lc_messages, "en_"))
{
/* TRANSLATORS: Replace LANG_CODE in this URL with your language code
<http://translationproject.org/team/LANG_CODE.html> to form one of