mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
use STREQ, not strcmp: part 1
git grep -l 'strcmp *([^=]*== *0'|xargs \ perl -pi -e 's/\bstrcmp( *\(.*?\)) *== *0/STREQ$1/g'
This commit is contained in:
@@ -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]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -78,9 +78,9 @@ do_tune2fs_l (const char *device)
|
||||
free (out);
|
||||
return NULL;
|
||||
}
|
||||
if (strcmp (colon, "<none>") == 0 ||
|
||||
strcmp (colon, "<not available>") == 0 ||
|
||||
strcmp (colon, "(none)") == 0) {
|
||||
if (STREQ (colon, "<none>") ||
|
||||
STREQ (colon, "<not available>") ||
|
||||
STREQ (colon, "(none)")) {
|
||||
if (add_string (&ret, &size, &alloc, "") == -1) {
|
||||
free (out);
|
||||
return NULL;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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: */
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 ("<windows/>\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 ("<uuid>%s</uuid>\n", sbfields[i+1]);
|
||||
else if (strcmp (sbfields[i], "Block size") == 0)
|
||||
else if (STREQ (sbfields[i], "Block size"))
|
||||
printf ("<blocksize>%s</blocksize>\n", sbfields[i+1]);
|
||||
|
||||
free (sbfields[i]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user