summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-06-23 10:11:25 +0200
committerJim Meyering <jim@meyering.net>2007-06-23 10:11:25 +0200
commit519d7a95a3f8103925aa84f9bdef326ce88d37cc (patch)
treec4a82988e9651e115fa1c2cccc6227cb136de4fa
parenta0304574e96916f0444b04f301f8e5191615f800 (diff)
downloadcoreutils-519d7a95a3f8103925aa84f9bdef326ce88d37cc.tar.xz
Prefer "STREQ (a, b)" over "strcmp (a, b) == 0"; similar for != 0.
* src/base64.c (main): Likewise. * src/install.c (setdefaultfilecon): Likewise. * src/sort.c (main): Likewise. * Makefile.maint (sc_prohibit_strcmp): New rule. * .x-sc_prohibit_strcmp: New file, to list the few exceptions. * Makefile.am (EXTRA_DIST): Add .x-sc_prohibit_strcmp.
-rw-r--r--.x-sc_prohibit_strcmp2
-rw-r--r--ChangeLog10
-rw-r--r--Makefile.am1
-rw-r--r--Makefile.maint7
-rw-r--r--src/base64.c4
-rw-r--r--src/install.c2
-rw-r--r--src/sort.c2
7 files changed, 24 insertions, 4 deletions
diff --git a/.x-sc_prohibit_strcmp b/.x-sc_prohibit_strcmp
new file mode 100644
index 000000000..fdceaf00b
--- /dev/null
+++ b/.x-sc_prohibit_strcmp
@@ -0,0 +1,2 @@
+^src/system\.h
+ChangeLog
diff --git a/ChangeLog b/ChangeLog
index aab0bc274..7244fa8e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-06-23 Jim Meyering <jim@meyering.net>
+
+ Prefer "STREQ (a, b)" over "strcmp (a, b) == 0"; similar for != 0.
+ * src/base64.c (main): Likewise.
+ * src/install.c (setdefaultfilecon): Likewise.
+ * src/sort.c (main): Likewise.
+ * Makefile.maint (sc_prohibit_strcmp): New rule.
+ * .x-sc_prohibit_strcmp: New file, to list the few exceptions.
+ * Makefile.am (EXTRA_DIST): Add .x-sc_prohibit_strcmp.
+
2007-06-22 Paul Eggert <eggert@cs.ucla.edu>
* NEWS: seq no longer mishandles obvious cases like
diff --git a/Makefile.am b/Makefile.am
index 1a6307717..5341edcaf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -26,6 +26,7 @@ EXTRA_DIST = Makefile.cfg Makefile.maint GNUmakefile \
.x-po-check \
.x-sc_file_system .x-sc_obsolete_symbols \
.x-sc_prohibit_atoi_atof \
+ .x-sc_prohibit_strcmp \
.x-sc_require_config_h \
.x-sc_space_tab .x-sc_sun_os_names \
.x-sc_trailing_blank \
diff --git a/Makefile.maint b/Makefile.maint
index bb666a4ad..04efbc297 100644
--- a/Makefile.maint
+++ b/Makefile.maint
@@ -125,6 +125,13 @@ sc_prohibit_atoi_atof:
{ echo '$(ME): do not use *scan''f, ato''f, ato''i, ato''l, ato''ll, ato''q, or ss''canf' \
1>&2; exit 1; } || :
+# Use STREQ rather than comparing strcmp == 0, or != 0.
+sc_prohibit_strcmp:
+ @grep -nE '! *str''cmp \(|\<str''cmp \([^)]+\) *==' \
+ $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): use STREQ in place of the above uses of str''cmp' \
+ 1>&2; exit 1; } || :
+
# Using EXIT_SUCCESS as the first argument to error is misleading,
# since when that parameter is 0, error does not exit. Use `0' instead.
sc_error_exit_success:
diff --git a/src/base64.c b/src/base64.c
index 4a278278e..3a38ccf5c 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -296,7 +296,7 @@ main (int argc, char **argv)
else
infile = "-";
- if (strcmp (infile, "-") == 0)
+ if (STREQ (infile, "-"))
input_fh = stdin;
else
{
@@ -312,7 +312,7 @@ main (int argc, char **argv)
if (fclose (input_fh) == EOF)
{
- if (strcmp (infile, "-") == 0)
+ if (STREQ (infile, "-"))
error (EXIT_FAILURE, errno, _("closing standard input"));
else
error (EXIT_FAILURE, errno, "%s", infile);
diff --git a/src/install.c b/src/install.c
index 39d514957..566c93c4d 100644
--- a/src/install.c
+++ b/src/install.c
@@ -217,7 +217,7 @@ setdefaultfilecon (char const *file)
/* If there's an error determining the context, or it has none,
return to allow default context */
if ((matchpathcon (file, st.st_mode, &scontext) != 0) ||
- (strcmp (scontext, "<<none>>") == 0))
+ STREQ (scontext, "<<none>>"))
{
if (scontext != NULL)
freecon (scontext);
diff --git a/src/sort.c b/src/sort.c
index ff021aa92..7290172b8 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -2930,7 +2930,7 @@ main (int argc, char **argv)
break;
case COMPRESS_PROGRAM_OPTION:
- if (compress_program && strcmp (compress_program, optarg) != 0)
+ if (compress_program && !STREQ (compress_program, optarg))
error (SORT_FAILURE, 0, _("multiple compress programs specified"));
compress_program = optarg;
break;