]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Prefer "STREQ (a, b)" over "strcmp (a, b) == 0"; similar for != 0.
authorJim Meyering <jim@meyering.net>
Sat, 23 Jun 2007 08:11:25 +0000 (10:11 +0200)
committerJim Meyering <jim@meyering.net>
Sat, 23 Jun 2007 08:11:25 +0000 (10:11 +0200)
* 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.

.x-sc_prohibit_strcmp [new file with mode: 0644]
ChangeLog
Makefile.am
Makefile.maint
src/base64.c
src/install.c
src/sort.c

diff --git a/.x-sc_prohibit_strcmp b/.x-sc_prohibit_strcmp
new file mode 100644 (file)
index 0000000..fdceaf0
--- /dev/null
@@ -0,0 +1,2 @@
+^src/system\.h
+ChangeLog
index aab0bc274f700717a3c134e530846b7f6874acd2..7244fa8e9af253b800138f90ed04af2459f47d3f 100644 (file)
--- 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
index 1a6307717f42ba9e2f7c6d6bb2320d9bb04478bc..5341edcaf650c57ed1c653b949c746f4a76bbaca 100644 (file)
@@ -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 \
index bb666a4adae10538ec0c8b55270d1505dca5eb9c..04efbc297e5201d4fbc52913754dd4fc22c81d75 100644 (file)
@@ -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:
index 4a278278e6295d2bf640b22dee931729ef50c3fb..3a38ccf5c0b0818019ea1e0461ff33bb65b106b7 100644 (file)
@@ -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);
index 39d514957599eb2279620b0d3d820e979e35071c..566c93c4dc2610bba2b8a0d70b3c674ae76f265c 100644 (file)
@@ -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);
index ff021aa9210c2e0b9c284036d4daf28efcc39cc8..7290172b8c663183b27fdc1bd12046750f094518 100644 (file)
@@ -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;