From 9a8889e4d0c532b9f77af3a9cc7aae06adebfb83 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 9 Nov 2009 14:30:11 +0100 Subject: [PATCH] use STREQ, not strcmp: part 1 git grep -l 'strcmp *([^=]*== *0'|xargs \ perl -pi -e 's/\bstrcmp( *\(.*?\)) *== *0/STREQ$1/g' --- capitests/test-command.c | 22 +++++++++++----------- daemon/debug.c | 2 +- daemon/dir.c | 2 +- daemon/ext2.c | 6 +++--- daemon/file.c | 4 ++-- daemon/guestfsd.c | 2 +- daemon/ls.c | 2 +- daemon/mkfs.c | 8 ++++---- daemon/mount.c | 2 +- daemon/xattr.c | 2 +- examples/to-xml.c | 6 +++--- fish/destpaths.c | 2 +- fish/fish.c | 8 ++++---- fuse/dircache.c | 8 ++++---- fuse/guestmount.c | 10 +++++----- hivex/hivex.c | 2 +- src/generator.ml | 6 +++--- src/guestfs.c | 18 +++++++++--------- test-tool/test-tool.c | 6 +++--- 19 files changed, 59 insertions(+), 59 deletions(-) diff --git a/capitests/test-command.c b/capitests/test-command.c index d451ebe..c43353d 100644 --- a/capitests/test-command.c +++ b/capitests/test-command.c @@ -30,27 +30,27 @@ int main (int argc, char *argv[]) { if (argc > 1) { - if (strcmp (argv[1], "1") == 0) { + if (STREQ (argv[1], "1")) { printf ("Result1"); - } else if (strcmp (argv[1], "2") == 0) { + } else if (STREQ (argv[1], "2")) { printf ("Result2\n"); - } else if (strcmp (argv[1], "3") == 0) { + } else if (STREQ (argv[1], "3")) { printf ("\nResult3"); - } else if (strcmp (argv[1], "4") == 0) { + } else if (STREQ (argv[1], "4")) { printf ("\nResult4\n"); - } else if (strcmp (argv[1], "5") == 0) { + } else if (STREQ (argv[1], "5")) { printf ("\nResult5\n\n"); - } else if (strcmp (argv[1], "6") == 0) { + } else if (STREQ (argv[1], "6")) { printf ("\n\nResult6\n\n"); - } else if (strcmp (argv[1], "7") == 0) { + } else if (STREQ (argv[1], "7")) { /* nothing */ - } else if (strcmp (argv[1], "8") == 0) { + } else if (STREQ (argv[1], "8")) { printf ("\n"); - } else if (strcmp (argv[1], "9") == 0) { + } else if (STREQ (argv[1], "9")) { printf ("\n\n"); - } else if (strcmp (argv[1], "10") == 0) { + } else if (STREQ (argv[1], "10")) { printf ("Result10-1\nResult10-2\n"); - } else if (strcmp (argv[1], "11") == 0) { + } else if (STREQ (argv[1], "11")) { printf ("Result11-1\nResult11-2"); } else { fprintf (stderr, "unknown parameter: %s\n", argv[1]); diff --git a/daemon/debug.c b/daemon/debug.c index 04c52f0..cb905cb 100644 --- a/daemon/debug.c +++ b/daemon/debug.c @@ -150,7 +150,7 @@ debug_fds (const char *subcmd, int argc, char *const *const argv) } while ((d = readdir (dir)) != NULL) { - if (strcmp (d->d_name, ".") == 0 || strcmp (d->d_name, "..") == 0) + if (STREQ (d->d_name, ".") || STREQ (d->d_name, "..")) continue; snprintf (fname, sizeof fname, "/proc/self/fd/%s", d->d_name); diff --git a/daemon/dir.c b/daemon/dir.c index b603cfd..a5076b1 100644 --- a/daemon/dir.c +++ b/daemon/dir.c @@ -56,7 +56,7 @@ do_rm_rf (const char *path) int r; char *buf, *err; - if (strcmp (path, "/") == 0) { + if (STREQ (path, "/")) { reply_with_error ("rm -rf: cannot remove root directory"); return -1; } diff --git a/daemon/ext2.c b/daemon/ext2.c index 14cbb3c..f768440 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -78,9 +78,9 @@ do_tune2fs_l (const char *device) free (out); return NULL; } - if (strcmp (colon, "") == 0 || - strcmp (colon, "") == 0 || - strcmp (colon, "(none)") == 0) { + if (STREQ (colon, "") || + STREQ (colon, "") || + STREQ (colon, "(none)")) { if (add_string (&ret, &size, &alloc, "") == -1) { free (out); return NULL; diff --git a/daemon/file.c b/daemon/file.c index 62de116..252c02c 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -481,9 +481,9 @@ do_zfile (const char *method, const char *path) FILE *fp; char line[256]; - if (strcmp (method, "gzip") == 0 || strcmp (method, "compress") == 0) + if (STREQ (method, "gzip") || STREQ (method, "compress")) zcat = "zcat"; - else if (strcmp (method, "bzip2") == 0) + else if (STREQ (method, "bzip2")) zcat = "bzcat"; else { reply_with_error ("zfile: unknown method"); diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 5789fed..db0bff9 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -831,7 +831,7 @@ split_lines (char *str) int size = 0, alloc = 0; char *p, *pend; - if (strcmp (str, "") == 0) + if (STREQ (str, "")) goto empty_list; p = str; diff --git a/daemon/ls.c b/daemon/ls.c index 3e3183a..0af2356 100644 --- a/daemon/ls.c +++ b/daemon/ls.c @@ -47,7 +47,7 @@ do_ls (const char *path) } while ((d = readdir (dir)) != NULL) { - if (strcmp (d->d_name, ".") == 0 || strcmp (d->d_name, "..") == 0) + if (STREQ (d->d_name, ".") || STREQ (d->d_name, "..")) continue; if (add_string (&r, &size, &alloc, d->d_name) == -1) { diff --git a/daemon/mkfs.c b/daemon/mkfs.c index 506066f..ba245b3 100644 --- a/daemon/mkfs.c +++ b/daemon/mkfs.c @@ -48,21 +48,21 @@ mkfs (const char *fstype, const char *device, * to every block and does bad block detection, neither of which * are useful behaviour for virtual devices. */ - if (strcmp (fstype, "ntfs") == 0) + if (STREQ (fstype, "ntfs")) argv[i++] = "-Q"; /* mkfs.reiserfs produces annoying interactive prompts unless you * tell it to be quiet. */ - if (strcmp (fstype, "reiserfs") == 0) + if (STREQ (fstype, "reiserfs")) argv[i++] = "-f"; /* Same for JFS. */ - if (strcmp (fstype, "jfs") == 0) + if (STREQ (fstype, "jfs")) argv[i++] = "-f"; /* For GFS, GFS2, assume a single node. */ - if (strcmp (fstype, "gfs") == 0 || strcmp (fstype, "gfs2") == 0) { + if (STREQ (fstype, "gfs") || STREQ (fstype, "gfs2")) { argv[i++] = "-p"; argv[i++] = "lock_nolock"; /* The man page says this is default, but it doesn't seem to be: */ diff --git a/daemon/mount.c b/daemon/mount.c index 5a27cea..49a0eab 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -50,7 +50,7 @@ do_mount_vfs (const char *options, const char *vfstype, ABS_PATH (mountpoint, return -1); - is_root = strcmp (mountpoint, "/") == 0; + is_root = STREQ (mountpoint, "/"); if (!root_mounted && !is_root) { reply_with_error ("mount: you must mount something on / first"); diff --git a/daemon/xattr.c b/daemon/xattr.c index d16939f..926baf0 100644 --- a/daemon/xattr.c +++ b/daemon/xattr.c @@ -410,7 +410,7 @@ do_lxattrlist (const char *path, char *const *names) fprintf (stderr, " %zu: special attrval = %s\n", k, entry[0].attrval.attrval_val); for (i = 1; k+i < ret->guestfs_int_xattr_list_len; ++i) { - if (strcmp (entry[i].attrname, "") == 0) + if (STREQ (entry[i].attrname, "")) break; fprintf (stderr, " name %s, value length %d\n", entry[i].attrname, entry[i].attrval.attrval_len); diff --git a/examples/to-xml.c b/examples/to-xml.c index 4317619..ee1b3bf 100644 --- a/examples/to-xml.c +++ b/examples/to-xml.c @@ -120,7 +120,7 @@ display_partition (guestfs_h *g, const char *dev) CALL (what = guestfs_file (g, dev), NULL); - if (strcmp (what, "x86 boot sector") == 0) + if (STREQ (what, "x86 boot sector")) /* This is what 'file' program shows for Windows/NTFS partitions. */ printf ("\n"); else if (strstr (what, "boot sector") != NULL) @@ -190,9 +190,9 @@ display_ext234 (guestfs_h *g, const char *dev, const char *fstype) /* Just pick out a few important fields to display. There * is much more that could be displayed here. */ - if (strcmp (sbfields[i], "Filesystem UUID") == 0) + if (STREQ (sbfields[i], "Filesystem UUID")) printf ("%s\n", sbfields[i+1]); - else if (strcmp (sbfields[i], "Block size") == 0) + else if (STREQ (sbfields[i], "Block size")) printf ("%s\n", sbfields[i+1]); free (sbfields[i]); diff --git a/fish/destpaths.c b/fish/destpaths.c index 9a3da82..02e9f22 100644 --- a/fish/destpaths.c +++ b/fish/destpaths.c @@ -168,7 +168,7 @@ complete_dest_paths_generator (const char *text, int state) if (strcmp (dirents->val[i].name, ".") != 0 && strcmp (dirents->val[i].name, "..") != 0) { - if (strcmp (dir, "/") == 0) + if (STREQ (dir, "/")) err = asprintf (&p, "/%s", dirents->val[i].name); else err = asprintf (&p, "%s/%s", dir, dirents->val[i].name); diff --git a/fish/fish.c b/fish/fish.c index cac4e4a..869366b 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -215,9 +215,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (strcmp (long_options[option_index].name, "listen") == 0) + if (STREQ (long_options[option_index].name, "listen")) remote_control_listen = 1; - else if (strcmp (long_options[option_index].name, "remote") == 0) { + else if (STREQ (long_options[option_index].name, "remote")) { if (optarg) { if (sscanf (optarg, "%d", &remote_control) != 1) { fprintf (stderr, _("%s: --listen=PID: PID was not a number: %s\n"), @@ -233,7 +233,7 @@ main (int argc, char *argv[]) exit (1); } } - } else if (strcmp (long_options[option_index].name, "selinux") == 0) { + } else if (STREQ (long_options[option_index].name, "selinux")) { guestfs_set_selinux (g, 1); } else { fprintf (stderr, _("%s: unknown long option: %s (%d)\n"), @@ -755,7 +755,7 @@ cmdline (char *argv[], int optind, int argc) if (optind >= argc) return; cmd = argv[optind++]; - if (strcmp (cmd, ":") == 0) { + if (STREQ (cmd, ":")) { fprintf (stderr, _("%s: empty command on command line\n"), program_name); exit (1); } diff --git a/fuse/dircache.c b/fuse/dircache.c index 545b9f3..1028926 100644 --- a/fuse/dircache.c +++ b/fuse/dircache.c @@ -100,7 +100,7 @@ gen_compare (void const *x, void const *y) { struct lsc_entry const *a = x; struct lsc_entry const *b = y; - return strcmp (a->pathname, b->pathname) == 0; + return STREQ (a->pathname, b->pathname); } static void @@ -250,7 +250,7 @@ lsc_insert (const char *path, const char *name, time_t now, free (entry); return -1; } - if (strcmp (path, "/") == 0) + if (STREQ (path, "/")) snprintf (entry->pathname, len, "/%s", name); else snprintf (entry->pathname, len, "%s/%s", path, name); @@ -285,7 +285,7 @@ xac_insert (const char *path, const char *name, time_t now, free (entry); return -1; } - if (strcmp (path, "/") == 0) + if (STREQ (path, "/")) snprintf (entry->pathname, len, "/%s", name); else snprintf (entry->pathname, len, "%s/%s", path, name); @@ -320,7 +320,7 @@ rlc_insert (const char *path, const char *name, time_t now, free (entry); return -1; } - if (strcmp (path, "/") == 0) + if (STREQ (path, "/")) snprintf (entry->pathname, len, "/%s", name); else snprintf (entry->pathname, len, "%s/%s", path, name); diff --git a/fuse/guestmount.c b/fuse/guestmount.c index 4547b3d..c7220c0 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -745,7 +745,7 @@ fg_getxattr (const char *path, const char *name, char *value, size_t i; int r = -ENOATTR; for (i = 0; i < xattrs->len; ++i) { - if (strcmp (xattrs->val[i].attrname, name) == 0) { + if (STREQ (xattrs->val[i].attrname, name)) { size_t sz = xattrs->val[i].attrval_len; if (sz > size) sz = size; @@ -993,13 +993,13 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (strcmp (long_options[option_index].name, "dir-cache-timeout") == 0) + if (STREQ (long_options[option_index].name, "dir-cache-timeout")) dir_cache_timeout = atoi (optarg); - else if (strcmp (long_options[option_index].name, "fuse-help") == 0) + else if (STREQ (long_options[option_index].name, "fuse-help")) fuse_help (); - else if (strcmp (long_options[option_index].name, "selinux") == 0) + else if (STREQ (long_options[option_index].name, "selinux")) guestfs_set_selinux (g, 1); - else if (strcmp (long_options[option_index].name, "trace") == 0) { + else if (STREQ (long_options[option_index].name, "trace")) { ADD_FUSE_ARG ("-f"); guestfs_set_trace (g, 1); guestfs_set_recovery_proc (g, 1); diff --git a/hivex/hivex.c b/hivex/hivex.c index 4b0deeb..e47dd23 100644 --- a/hivex/hivex.c +++ b/hivex/hivex.c @@ -235,7 +235,7 @@ hivex_open (const char *filename, int flags) h->msglvl = flags & HIVEX_OPEN_MSGLVL_MASK; const char *debug = getenv ("HIVEX_DEBUG"); - if (debug && strcmp (debug, "1") == 0) + if (debug && STREQ (debug, "1")) h->msglvl = 2; if (h->msglvl >= 2) diff --git a/src/generator.ml b/src/generator.ml index aff6356..917fea9 100644 --- a/src/generator.ml +++ b/src/generator.ml @@ -5878,9 +5878,9 @@ static int %s_skip (void) if (str) return strstr (str, \"%s\") == NULL; str = getenv (\"SKIP_%s\"); - if (str && strcmp (str, \"1\") == 0) return 1; + if (str && STREQ (str, \"1\")) return 1; str = getenv (\"SKIP_TEST_%s\"); - if (str && strcmp (str, \"1\") == 0) return 1; + if (str && STREQ (str, \"1\")) return 1; return 0; } @@ -9570,7 +9570,7 @@ print_strings (char *const *argv) pr " sscanf (val, \"%%\" SCNi64, &r);\n"; pr " return r;\n" | RBool _ -> - pr " return strcmp (val, \"true\") == 0;\n" + pr " return STREQ (val, \"true\");\n" | RConstString _ | RConstOptString _ -> (* Can't return the input string here. Return a static diff --git a/src/guestfs.c b/src/guestfs.c index f7df27e..c8b52c5 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -173,10 +173,10 @@ guestfs_create (void) g->recovery_proc = 1; str = getenv ("LIBGUESTFS_DEBUG"); - g->verbose = str != NULL && strcmp (str, "1") == 0; + g->verbose = str != NULL && STREQ (str, "1"); str = getenv ("LIBGUESTFS_TRACE"); - g->trace = str != NULL && strcmp (str, "1") == 0; + g->trace = str != NULL && STREQ (str, "1"); str = getenv ("LIBGUESTFS_PATH"); g->path = str != NULL ? strdup (str) : strdup (GUESTFS_DEFAULT_PATH); @@ -722,13 +722,13 @@ guestfs__config (guestfs_h *g, /* A bit fascist, but the user will probably break the extra * parameters that we add if they try to set any of these. */ - if (strcmp (qemu_param, "-kernel") == 0 || - strcmp (qemu_param, "-initrd") == 0 || - strcmp (qemu_param, "-nographic") == 0 || - strcmp (qemu_param, "-serial") == 0 || - strcmp (qemu_param, "-full-screen") == 0 || - strcmp (qemu_param, "-std-vga") == 0 || - strcmp (qemu_param, "-vnc") == 0) { + if (STREQ (qemu_param, "-kernel") || + STREQ (qemu_param, "-initrd") || + STREQ (qemu_param, "-nographic") || + STREQ (qemu_param, "-serial") || + STREQ (qemu_param, "-full-screen") || + STREQ (qemu_param, "-std-vga") || + STREQ (qemu_param, "-vnc")) { error (g, _("guestfs_config: parameter '%s' isn't allowed"), qemu_param); return -1; } diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c index 8a80f66..73f3af5 100644 --- a/test-tool/test-tool.c +++ b/test-tool/test-tool.c @@ -100,11 +100,11 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (strcmp (long_options[option_index].name, "helper") == 0) + if (STREQ (long_options[option_index].name, "helper")) helper = optarg; - else if (strcmp (long_options[option_index].name, "qemu") == 0) + else if (STREQ (long_options[option_index].name, "qemu")) set_qemu (optarg, 0); - else if (strcmp (long_options[option_index].name, "qemudir") == 0) + else if (STREQ (long_options[option_index].name, "qemudir")) set_qemu (optarg, 1); else { fprintf (stderr, -- 1.8.3.1