The series below makes changes like these mechanically,
one class of change per change-set:
strcmp(...) == 0 to STREQ(...)
strcmp(...) != 0 to STRNEQ(...)
strncmp(...) == 0 to STREQLEN(...)
strncmp(...) != 0 to STRNEQLEN(...)
strcasecmp(...) == 0 to STRCASEEQ(...)
strcasecmp(...) != 0 to STRCASENEQ(...)
strncasecmp(...) == 0 to STRCASEEQLEN(...)
strncasecmp(...) != 0 to STRCASENEQLEN(...)
Then it enables the "make syntax-check" tests to ensure
no offending (convertable) use is introduced.
But there's one twist.
In order for the substitution commands to work as-is,
I first converted str*cmp functions, and *then* added
the #define stmts. Afterwards, I used git rebase -i to
move the final #define-adding-commit to precede the others.
That makes it so that the code compiles after each new change set.
If I'd added the #defines before performing the substitutions,
I would have had to make the commands more involved to keep
them from transforming the #defines.
Just noticed that the actual definitions are
over-parenthesized, and can be simplified to this:
#define STREQ(a,b) (strcmp(a,b) == 0)
#define STRNEQ(a,b) (!STREQ(a,b))
#define STRCASEEQ(a,b) (strcasecmp(a,b) == 0)
#define STRCASENEQ(a,b) (!STRCASEEQ(a,b))
#define STREQLEN(a,b,n) (strncmp(a,b,n) == 0)
#define STRNEQLEN(a,b,n) (!STREQLEN(a,b,n))
#define STRCASEEQLEN(a,b,n) (strncasecmp(a,b,n) == 0)
#define STRCASENEQLEN(a,b,n) (!STRCASEEQLEN(a,b,n))
#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
I'll adjust to use the above tomorrow.
---------------------------------------------
From a reviewer's perspective, it's useful to know that 2-8
were done mechanically. Only 1 and 10 were done manually.
This has not yet passed "make check", possibly due to unrelated
problems.
From 7cd4b6aeee3693463b03608a31cf53f21152c2e8 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 19:50:22 +0100
Subject: [PATCH libguestfs 01/10] define STREQ, STRNEQ, STREQLEN, STRCASEQ, etc.
* src/guestfs.h: Define STREQ and company.
* daemon/daemon.h: Likewise.
* hivex/hivex.h: Likewise.
---
daemon/daemon.h | 10 ++++++++++
hivex/hivex.h | 10 ++++++++++
src/guestfs.h | 10 ++++++++++
3 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 8912840..3f4c480 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -234,4 +234,14 @@ extern void reply (xdrproc_t xdrp, char *ret);
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif
+#define STREQ(a,b) (strcmp((a),(b)) == 0)
+#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
+#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
+#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
+#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
+#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
+#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
+#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
+#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
+
#endif /* GUESTFSD_DAEMON_H */
diff --git a/hivex/hivex.h b/hivex/hivex.h
index 14bdcc5..be7feee 100644
--- a/hivex/hivex.h
+++ b/hivex/hivex.h
@@ -73,6 +73,16 @@ typedef enum hive_type hive_type;
#define HIVEX_OPEN_DEBUG 2
#define HIVEX_OPEN_MSGLVL_MASK 3
+#define STREQ(a,b) (strcmp((a),(b)) == 0)
+#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
+#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
+#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
+#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
+#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
+#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
+#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
+#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
+
extern hive_h *hivex_open (const char *filename, int flags);
extern int hivex_close (hive_h *h);
extern hive_node_h hivex_root (hive_h *h);
diff --git a/src/guestfs.h b/src/guestfs.h
index 35f995d..e89f744 100644
--- a/src/guestfs.h
+++ b/src/guestfs.h
@@ -30,6 +30,16 @@
extern "C" {
#endif
+#define STREQ(a,b) (strcmp((a),(b)) == 0)
+#define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
+#define STRNEQ(a,b) (strcmp((a),(b)) != 0)
+#define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
+#define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
+#define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
+#define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
+#define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
+#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
+
typedef struct guestfs_h guestfs_h;
/* Connection management. */
--
1.6.5.2.351.g0943
From 9353c6253d5fac1648b13ad9958468a2d9f6ad6f Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 13:58:42 +0100
Subject: [PATCH libguestfs 02/10] convert uses of strcasecmp to STRCASEEQ
git grep -l 'strcasecmp *([^=]*== *0'| xargs \
perl -pi -e 's/\bstrcasecmp( *\(.*?\)) *== *0/STRCASEEQ$1/'
---
daemon/checksum.c | 14 +++++-----
daemon/debug.c | 2 +-
daemon/realpath.c | 2 +-
fish/edit.c | 4 +-
fish/fish.c | 68 ++++++++++++++++++++++++++--------------------------
fish/more.c | 2 +-
hivex/hivex.c | 4 +-
src/generator.ml | 12 ++++----
8 files changed, 54 insertions(+), 54 deletions(-)
diff --git a/daemon/checksum.c b/daemon/checksum.c
index 2423265..499d19d 100644
--- a/daemon/checksum.c
+++ b/daemon/checksum.c
@@ -36,19 +36,19 @@ do_checksum (const char *csumtype, const char *path)
int r;
int len;
- if (strcasecmp (csumtype, "crc") == 0)
+ if (STRCASEEQ (csumtype, "crc"))
program = "cksum";
- else if (strcasecmp (csumtype, "md5") == 0)
+ else if (STRCASEEQ (csumtype, "md5"))
program = "md5sum";
- else if (strcasecmp (csumtype, "sha1") == 0)
+ else if (STRCASEEQ (csumtype, "sha1"))
program = "sha1sum";
- else if (strcasecmp (csumtype, "sha224") == 0)
+ else if (STRCASEEQ (csumtype, "sha224"))
program = "sha224sum";
- else if (strcasecmp (csumtype, "sha256") == 0)
+ else if (STRCASEEQ (csumtype, "sha256"))
program = "sha256sum";
- else if (strcasecmp (csumtype, "sha384") == 0)
+ else if (STRCASEEQ (csumtype, "sha384"))
program = "sha384sum";
- else if (strcasecmp (csumtype, "sha512") == 0)
+ else if (STRCASEEQ (csumtype, "sha512"))
program = "sha512sum";
else {
reply_with_error ("unknown checksum type, expecting
crc|md5|sha1|sha224|sha256|sha384|sha512");
diff --git a/daemon/debug.c b/daemon/debug.c
index 8daa032..04c52f0 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -80,7 +80,7 @@ do_debug (const char *subcmd MAYBE_UNUSED, char *const *argv
MAYBE_UNUSED)
argc++;
for (i = 0; cmds[i].cmd != NULL; ++i) {
- if (strcasecmp (subcmd, cmds[i].cmd) == 0)
+ if (STRCASEEQ (subcmd, cmds[i].cmd))
return cmds[i].f (subcmd, argc, argv);
}
diff --git a/daemon/realpath.c b/daemon/realpath.c
index 0dc5fa5..17e74ea 100644
--- a/daemon/realpath.c
+++ b/daemon/realpath.c
@@ -113,7 +113,7 @@ do_case_sensitive_path (const char *path)
errno = 0;
while ((d = readdir (dir)) != NULL) {
- if (strcasecmp (d->d_name, name) == 0)
+ if (STRCASEEQ (d->d_name, name))
break;
}
diff --git a/fish/edit.c b/fish/edit.c
index 1b6ce23..d30b3ca 100644
--- a/fish/edit.c
+++ b/fish/edit.c
@@ -88,9 +88,9 @@ do_edit (const char *cmd, int argc, char *argv[])
}
/* Choose an editor. */
- if (strcasecmp (cmd, "vi") == 0)
+ if (STRCASEEQ (cmd, "vi"))
editor = "vi";
- else if (strcasecmp (cmd, "emacs") == 0)
+ else if (STRCASEEQ (cmd, "emacs"))
editor = "emacs -nw";
else {
editor = getenv ("EDITOR");
diff --git a/fish/fish.c b/fish/fish.c
index 3ab09b5..9a89f55 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -843,40 +843,40 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
r = rc_remote (remote_control, cmd, argc, argv, exit_on_error);
/* Otherwise execute it locally. */
- else if (strcasecmp (cmd, "help") == 0) {
+ else if (STRCASEEQ (cmd, "help")) {
if (argc == 0)
list_commands ();
else
display_command (argv[0]);
r = 0;
}
- else if (strcasecmp (cmd, "quit") == 0 ||
- strcasecmp (cmd, "exit") == 0 ||
- strcasecmp (cmd, "q") == 0) {
+ else if (STRCASEEQ (cmd, "quit") ||
+ STRCASEEQ (cmd, "exit") ||
+ STRCASEEQ (cmd, "q")) {
quit = 1;
r = 0;
}
- else if (strcasecmp (cmd, "alloc") == 0 ||
- strcasecmp (cmd, "allocate") == 0)
+ else if (STRCASEEQ (cmd, "alloc") ||
+ STRCASEEQ (cmd, "allocate"))
r = do_alloc (cmd, argc, argv);
- else if (strcasecmp (cmd, "echo") == 0)
+ else if (STRCASEEQ (cmd, "echo"))
r = do_echo (cmd, argc, argv);
- else if (strcasecmp (cmd, "edit") == 0 ||
- strcasecmp (cmd, "vi") == 0 ||
- strcasecmp (cmd, "emacs") == 0)
+ else if (STRCASEEQ (cmd, "edit") ||
+ STRCASEEQ (cmd, "vi") ||
+ STRCASEEQ (cmd, "emacs"))
r = do_edit (cmd, argc, argv);
- else if (strcasecmp (cmd, "lcd") == 0)
+ else if (STRCASEEQ (cmd, "lcd"))
r = do_lcd (cmd, argc, argv);
- else if (strcasecmp (cmd, "glob") == 0)
+ else if (STRCASEEQ (cmd, "glob"))
r = do_glob (cmd, argc, argv);
- else if (strcasecmp (cmd, "more") == 0 ||
- strcasecmp (cmd, "less") == 0)
+ else if (STRCASEEQ (cmd, "more") ||
+ STRCASEEQ (cmd, "less"))
r = do_more (cmd, argc, argv);
- else if (strcasecmp (cmd, "reopen") == 0)
+ else if (STRCASEEQ (cmd, "reopen"))
r = do_reopen (cmd, argc, argv);
- else if (strcasecmp (cmd, "sparse") == 0)
+ else if (STRCASEEQ (cmd, "sparse"))
r = do_sparse (cmd, argc, argv);
- else if (strcasecmp (cmd, "time") == 0)
+ else if (STRCASEEQ (cmd, "time"))
r = do_time (cmd, argc, argv);
else
r = run_action (cmd, argc, argv);
@@ -941,8 +941,8 @@ display_builtin_command (const char *cmd)
{
/* help for actions is auto-generated, see display_command */
- if (strcasecmp (cmd, "alloc") == 0 ||
- strcasecmp (cmd, "allocate") == 0)
+ if (STRCASEEQ (cmd, "alloc") ||
+ STRCASEEQ (cmd, "allocate"))
printf (_("alloc - allocate an image\n"
" alloc <filename> <size>\n"
"\n"
@@ -961,14 +961,14 @@ display_builtin_command (const char *cmd)
" <nn>P or <nn>PB number of petabytes\n"
" <nn>E or <nn>EB number of exabytes\n"
" <nn>sects number of 512 byte sectors\n"));
- else if (strcasecmp (cmd, "echo") == 0)
+ else if (STRCASEEQ (cmd, "echo"))
printf (_("echo - display a line of text\n"
" echo [<params> ...]\n"
"\n"
" This echos the parameters to the terminal.\n"));
- else if (strcasecmp (cmd, "edit") == 0 ||
- strcasecmp (cmd, "vi") == 0 ||
- strcasecmp (cmd, "emacs") == 0)
+ else if (STRCASEEQ (cmd, "edit") ||
+ STRCASEEQ (cmd, "vi") ||
+ STRCASEEQ (cmd, "emacs"))
printf (_("edit - edit a file in the image\n"
" edit <filename>\n"
"\n"
@@ -982,26 +982,26 @@ display_builtin_command (const char *cmd)
"\n"
" NOTE: This will not work reliably for large files\n"
" (> 2 MB) or binary files containing \\0 bytes.\n"));
- else if (strcasecmp (cmd, "lcd") == 0)
+ else if (STRCASEEQ (cmd, "lcd"))
printf (_("lcd - local change directory\n"
" lcd <directory>\n"
"\n"
" Change guestfish's current directory. This command
is\n"
" useful if you want to download files to a particular\n"
" place.\n"));
- else if (strcasecmp (cmd, "glob") == 0)
+ else if (STRCASEEQ (cmd, "glob"))
printf (_("glob - expand wildcards in command\n"
" glob <command> [<args> ...]\n"
"\n"
" Glob runs <command> with wildcards expanded in any\n"
" command args. Note that the command is run repeatedly\n"
" once for each expanded argument.\n"));
- else if (strcasecmp (cmd, "help") == 0)
+ else if (STRCASEEQ (cmd, "help"))
printf (_("help - display a list of commands or help on a command\n"
" help cmd\n"
" help\n"));
- else if (strcasecmp (cmd, "more") == 0 ||
- strcasecmp (cmd, "less") == 0)
+ else if (STRCASEEQ (cmd, "more") ||
+ STRCASEEQ (cmd, "less"))
printf (_("more - view a file in the pager\n"
" more <filename>\n"
"\n"
@@ -1015,19 +1015,19 @@ display_builtin_command (const char *cmd)
"\n"
" NOTE: This will not work reliably for large files\n"
" (> 2 MB) or binary files containing \\0 bytes.\n"));
- else if (strcasecmp (cmd, "quit") == 0 ||
- strcasecmp (cmd, "exit") == 0 ||
- strcasecmp (cmd, "q") == 0)
+ else if (STRCASEEQ (cmd, "quit") ||
+ STRCASEEQ (cmd, "exit") ||
+ STRCASEEQ (cmd, "q"))
printf (_("quit - quit guestfish\n"
" quit\n"));
- else if (strcasecmp (cmd, "reopen") == 0)
+ else if (STRCASEEQ (cmd, "reopen"))
printf (_("reopen - close and reopen the libguestfs handle\n"
" reopen\n"
"\n"
"Close and reopen the libguestfs handle. It is not necessary to
use\n"
"this normally, because the handle is closed properly when
guestfish\n"
"exits. However this is occasionally useful for testing.\n"));
- else if (strcasecmp (cmd, "sparse") == 0)
+ else if (STRCASEEQ (cmd, "sparse"))
printf (_("sparse - allocate a sparse image file\n"
" sparse <filename> <size>\n"
"\n"
@@ -1054,7 +1054,7 @@ display_builtin_command (const char *cmd)
" <nn>P or <nn>PB number of petabytes\n"
" <nn>E or <nn>EB number of exabytes\n"
" <nn>sects number of 512 byte sectors\n"));
- else if (strcasecmp (cmd, "time") == 0)
+ else if (STRCASEEQ (cmd, "time"))
printf (_("time - measure time taken to run command\n"
" time <command> [<args> ...]\n"
"\n"
diff --git a/fish/more.c b/fish/more.c
index 9abb51b..a32d5b4 100644
--- a/fish/more.c
+++ b/fish/more.c
@@ -42,7 +42,7 @@ do_more (const char *cmd, int argc, char *argv[])
}
/* Choose a pager. */
- if (strcasecmp (cmd, "less") == 0)
+ if (STRCASEEQ (cmd, "less"))
pager = "less";
else {
pager = getenv ("PAGER");
diff --git a/hivex/hivex.c b/hivex/hivex.c
index b20fe73..8ea2c2b 100644
--- a/hivex/hivex.c
+++ b/hivex/hivex.c
@@ -725,7 +725,7 @@ hivex_node_get_child (hive_h *h, hive_node_h node, const char *nname)
for (i = 0; children[i] != 0; ++i) {
name = hivex_node_name (h, children[i]);
if (!name) goto error;
- if (strcasecmp (name, nname) == 0) {
+ if (STRCASEEQ (name, nname)) {
ret = children[i];
break;
}
@@ -856,7 +856,7 @@ hivex_node_get_value (hive_h *h, hive_node_h node, const char *key)
for (i = 0; values[i] != 0; ++i) {
name = hivex_value_key (h, values[i]);
if (!name) goto error;
- if (strcasecmp (name, key) == 0) {
+ if (STRCASEEQ (name, key)) {
ret = values[i];
break;
}
diff --git a/src/generator.ml b/src/generator.ml
index 17519fe..3a25c57 100644
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -6430,11 +6430,11 @@ and generate_fish_cmds () =
else "" in
pr " if (";
- pr "strcasecmp (cmd, \"%s\") == 0" name;
+ pr "STRCASEEQ (cmd, \"%s\")" name;
if name <> name2 then
- pr " || strcasecmp (cmd, \"%s\") == 0" name2;
+ pr " || STRCASEEQ (cmd, \"%s\")" name2;
if name <> alias then
- pr " || strcasecmp (cmd, \"%s\") == 0" alias;
+ pr " || STRCASEEQ (cmd, \"%s\")" alias;
pr ")\n";
pr " pod2text (\"%s\", _(\"%s\"), %S);\n"
name2 shortdesc
@@ -6692,11 +6692,11 @@ and generate_fish_cmds () =
try find_map (function FishAlias n -> Some n | _ -> None) flags
with Not_found -> name in
pr " if (";
- pr "strcasecmp (cmd, \"%s\") == 0" name;
+ pr "STRCASEEQ (cmd, \"%s\")" name;
if name <> name2 then
- pr " || strcasecmp (cmd, \"%s\") == 0" name2;
+ pr " || STRCASEEQ (cmd, \"%s\")" name2;
if name <> alias then
- pr " || strcasecmp (cmd, \"%s\") == 0" alias;
+ pr " || STRCASEEQ (cmd, \"%s\")" alias;
pr ")\n";
pr " return run_%s (cmd, argc, argv);\n" name;
pr " else\n";
--
1.6.5.2.351.g0943
From 29842da1379ece83eae98ee786b475ae161f1687 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 14:06:37 +0100
Subject: [PATCH libguestfs 03/10] convert strcasecmp(...) != 0 to STRCASENEQ(...)
git grep -E -l 'strcasecmp *\(.*!= ?0\b'|xargs \
perl -pi -e 's/\bstrcasecmp( ?\(.*?\)) != 0/STRCASENEQ$1/g'
---
fish/fish.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/fish/fish.c b/fish/fish.c
index 9a89f55..cac4e4a 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -1107,11 +1107,11 @@ int
is_true (const char *str)
{
return
- strcasecmp (str, "0") != 0 &&
- strcasecmp (str, "f") != 0 &&
- strcasecmp (str, "false") != 0 &&
- strcasecmp (str, "n") != 0 &&
- strcasecmp (str, "no") != 0;
+ STRCASENEQ (str, "0") &&
+ STRCASENEQ (str, "f") &&
+ STRCASENEQ (str, "false") &&
+ STRCASENEQ (str, "n") &&
+ STRCASENEQ (str, "no");
}
/* Free strings from a non-NULL terminated char** */
--
1.6.5.2.351.g0943
From 627f89351d06e43564b47ea42cabaa522284c2a1 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 14:21:46 +0100
Subject: [PATCH libguestfs 04/10] change strncmp(...) != 0 to STRNEQLEN(...)
git grep -l 'strncmp *([^=]*!= *0'|xargs \
perl -pi -e 's/\bstrncmp( *\(.*?\)) *!= *0/STRNEQLEN$1/g'
---
daemon/daemon.h | 2 +-
daemon/guestfsd.c | 2 +-
examples/to-xml.c | 2 +-
src/generator.ml | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 3f4c480..1cdb480 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -164,7 +164,7 @@ extern void reply (xdrproc_t xdrp, char *ret);
*/
#define RESOLVE_DEVICE(path,fail_stmt) \
do { \
- if (strncmp ((path), "/dev/", 5) != 0) { \
+ if (STRNEQLEN ((path), "/dev/", 5)) { \
reply_with_error ("%s: %s: expecting a device name", __func__, (path));
\
fail_stmt; \
} \
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index d16826f..61a6236 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -945,7 +945,7 @@ device_name_translation (char *device, const char *func)
}
/* If the name begins with "/dev/sd" then try the alternatives. */
- if (strncmp (device, "/dev/sd", 7) != 0)
+ if (STRNEQLEN (device, "/dev/sd", 7))
goto error;
device[5] = 'h'; /* /dev/hd (old IDE driver) */
diff --git a/examples/to-xml.c b/examples/to-xml.c
index 6d0a1df..f48d1ca 100644
--- a/examples/to-xml.c
+++ b/examples/to-xml.c
@@ -149,7 +149,7 @@ display_partitions (guestfs_h *g, const char *dev)
* That's a limitation of sorts of the Linux kernel. (Actually,
* we could do this if we add the kpartx program to libguestfs).
*/
- if (strncmp (dev, "/dev/sd", 7) != 0 || isdigit (dev[strlen(dev)-1])) {
+ if (STRNEQLEN (dev, "/dev/sd", 7) || isdigit (dev[strlen(dev)-1])) {
printf ("<vm-image dev=\"%s\"/>\n", dev);
return;
}
diff --git a/src/generator.ml b/src/generator.ml
index 3a25c57..aff6356 100644
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -6146,7 +6146,7 @@ and generate_one_test_body name i test_name init test =
pr " fprintf (stderr, \"%s: returned size of buffer wrong,
expected %d but got %%zu\\n\", size);\n" test_name len;
pr " return -1;\n";
pr " }\n";
- pr " if (strncmp (r, expected, size) != 0) {\n";
+ pr " if (STRNEQLEN (r, expected, size)) {\n";
pr " fprintf (stderr, \"%s: expected \\\"%%s\\\" but got
\\\"%%s\\\"\\n\", expected, r);\n" test_name;
pr " return -1;\n";
pr " }\n"
--
1.6.5.2.351.g0943
From 3e70b34eed5a48640e20fbf6dcba774aaace1f3c Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 14:26:21 +0100
Subject: [PATCH libguestfs 05/10] change strncmp() == 0 to STREQLEN()
git grep -l 'strncmp *([^=]*== *0'|xargs \
perl -pi -e 's/\bstrncmp( *\(.*?\)) *== *0\b/STREQLEN$1/g'
---
daemon/daemon.h | 2 +-
daemon/devsparts.c | 10 +++++-----
daemon/ext2.c | 2 +-
daemon/file.c | 2 +-
daemon/guestfsd.c | 2 +-
daemon/mount.c | 2 +-
daemon/upload.c | 4 ++--
examples/to-xml.c | 8 ++++----
fish/destpaths.c | 2 +-
fish/edit.c | 2 +-
fish/tilde.c | 2 +-
hivex/hivex.c | 2 +-
test-tool/test-tool.c | 2 +-
13 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 1cdb480..ac68479 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -184,7 +184,7 @@ extern void reply (xdrproc_t xdrp, char *ret);
*/
#define REQUIRE_ROOT_OR_RESOLVE_DEVICE(path,fail_stmt) \
do { \
- if (strncmp ((path), "/dev/", 5) == 0) \
+ if (STREQLEN ((path), "/dev/", 5)) \
RESOLVE_DEVICE ((path), fail_stmt); \
else { \
NEED_ROOT (fail_stmt); \
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index 76852cc..60e7aa8 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -53,10 +53,10 @@ foreach_block_device (block_dev_func_t func)
struct dirent *d = readdir(dir);
if(NULL == d) break;
- if (strncmp (d->d_name, "sd", 2) == 0 ||
- strncmp (d->d_name, "hd", 2) == 0 ||
- strncmp (d->d_name, "vd", 2) == 0 ||
- strncmp (d->d_name, "sr", 2) == 0) {
+ if (STREQLEN (d->d_name, "sd", 2) ||
+ STREQLEN (d->d_name, "hd", 2) ||
+ STREQLEN (d->d_name, "vd", 2) ||
+ STREQLEN (d->d_name, "sr", 2)) {
char dev_path[256];
snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
@@ -153,7 +153,7 @@ add_partitions(const char *device,
errno = 0;
struct dirent *d;
while ((d = readdir (dir)) != NULL) {
- if (strncmp (d->d_name, device, strlen (device)) == 0) {
+ if (STREQLEN (d->d_name, device, strlen (device))) {
char part[256];
snprintf (part, sizeof part, "/dev/%s", d->d_name);
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 0021a06..14cbb3c 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -48,7 +48,7 @@ do_tune2fs_l (const char *device)
p = out;
/* Discard the first line if it contains "tune2fs ...". */
- if (strncmp (p, "tune2fs ", 8) == 0) {
+ if (STREQLEN (p, "tune2fs ", 8)) {
p = strchr (p, '\n');
if (p) p++;
else {
diff --git a/daemon/file.c b/daemon/file.c
index 7854ade..62de116 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -430,7 +430,7 @@ do_file (const char *path)
char *buf;
int len;
- if (strncmp (path, "/dev/", 5) == 0)
+ if (STREQLEN (path, "/dev/", 5))
buf = (char *) path;
else {
buf = sysroot_path (path);
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 61a6236..5789fed 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -226,7 +226,7 @@ main (int argc, char *argv[])
/* Connect to vmchannel. */
int sock = -1;
- if (strncmp (vmchannel, "tcp:", 4) == 0) {
+ if (STREQLEN (vmchannel, "tcp:", 4)) {
/* Resolve the hostname. */
struct addrinfo *res, *rr;
struct addrinfo hints;
diff --git a/daemon/mount.c b/daemon/mount.c
index 463e789..5a27cea 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -112,7 +112,7 @@ do_umount (const char *pathordevice)
char *buf;
int is_dev;
- is_dev = strncmp (pathordevice, "/dev/", 5) == 0;
+ is_dev = STREQLEN (pathordevice, "/dev/", 5);
buf = is_dev ? strdup (pathordevice)
: sysroot_path (pathordevice);
if (buf == NULL) {
diff --git a/daemon/upload.c b/daemon/upload.c
index da86bd6..7b2ccea 100644
--- a/daemon/upload.c
+++ b/daemon/upload.c
@@ -40,7 +40,7 @@ do_upload (const char *filename)
{
int err, fd, r, is_dev;
- is_dev = strncmp (filename, "/dev/", 5) == 0;
+ is_dev = STREQLEN (filename, "/dev/", 5);
if (!is_dev) {
if (!root_mounted || filename[0] != '/') {
cancel_receive ();
@@ -93,7 +93,7 @@ do_download (const char *filename)
int fd, r, is_dev;
char buf[GUESTFS_MAX_CHUNK_SIZE];
- is_dev = strncmp (filename, "/dev/", 5) == 0;
+ is_dev = STREQLEN (filename, "/dev/", 5);
if (!is_dev) CHROOT_IN;
fd = open (filename, O_RDONLY);
diff --git a/examples/to-xml.c b/examples/to-xml.c
index f48d1ca..4317619 100644
--- a/examples/to-xml.c
+++ b/examples/to-xml.c
@@ -87,8 +87,8 @@ main (int argc, char *argv[])
int len = strlen (vgs[i]);
int j;
for (j = 0; lvs[j] != NULL; ++j) {
- if (strncmp (lvs[j], "/dev/", 5) == 0 &&
- strncmp (&lvs[j][5], vgs[i], len) == 0 &&
+ if (STREQLEN (lvs[j], "/dev/", 5) &&
+ STREQLEN (&lvs[j][5], vgs[i], len) &&
lvs[j][len+5] == '/') {
int64_t size;
CALL (size = guestfs_blockdev_getsize64 (g, lvs[j]), -1);
@@ -125,7 +125,7 @@ display_partition (guestfs_h *g, const char *dev)
printf ("<windows/>\n");
else if (strstr (what, "boot sector") != NULL)
display_partitions (g, dev);
- else if (strncmp (what, "LVM2", 4) == 0)
+ else if (STREQLEN (what, "LVM2", 4))
printf ("<physvol/>\n");
else if (strstr (what, "ext2 filesystem data") != NULL)
display_ext234 (g, dev, "ext2");
@@ -162,7 +162,7 @@ display_partitions (guestfs_h *g, const char *dev)
len = strlen (dev);
for (i = 0; parts[i] != NULL; ++i) {
/* Only display partition if it's in the device. */
- if (strncmp (parts[i], dev, len) == 0) {
+ if (STREQLEN (parts[i], dev, len)) {
int64_t size;
CALL (size = guestfs_blockdev_getsize64 (g, parts[i]), -1);
printf ("<partition dev=\"%s\" size=\"%" PRIi64
"\">\n", parts[i], size);
diff --git a/fish/destpaths.c b/fish/destpaths.c
index 1e42ae8..9a3da82 100644
--- a/fish/destpaths.c
+++ b/fish/destpaths.c
@@ -133,7 +133,7 @@ complete_dest_paths_generator (const char *text, int state)
} while (0)
/* Is it a device? */
- if (len < 5 || strncmp (text, "/dev/", 5) == 0) {
+ if (len < 5 || STREQLEN (text, "/dev/", 5)) {
/* Get a list of everything that can possibly begin with /dev/ */
strs = guestfs_list_devices (g);
APPEND_STRS_AND_FREE;
diff --git a/fish/edit.c b/fish/edit.c
index d30b3ca..3fc41fb 100644
--- a/fish/edit.c
+++ b/fish/edit.c
@@ -149,7 +149,7 @@ do_edit (const char *cmd, int argc, char *argv[])
unlink (filename);
/* Changed? */
- if (strlen (content) == size && strncmp (content, content_new, size) == 0) {
+ if (strlen (content) == size && STREQLEN (content, content_new, size)) {
free (content);
free (content_new);
return 0;
diff --git a/fish/tilde.c b/fish/tilde.c
index 1c52d3e..64b5b39 100644
--- a/fish/tilde.c
+++ b/fish/tilde.c
@@ -110,7 +110,7 @@ find_home_for_username (const char *username, size_t ulen)
setpwent ();
while ((pw = getpwent ()) != NULL) {
if (strlen (pw->pw_name) == ulen &&
- strncmp (username, pw->pw_name, ulen) == 0)
+ STREQLEN (username, pw->pw_name, ulen))
return pw->pw_dir;
}
diff --git a/hivex/hivex.c b/hivex/hivex.c
index 8ea2c2b..4b0deeb 100644
--- a/hivex/hivex.c
+++ b/hivex/hivex.c
@@ -143,7 +143,7 @@ struct ntreg_hbin_block {
} __attribute__((__packed__));
#define BLOCK_ID_EQ(h,offs,eqid) \
- (strncmp (((struct ntreg_hbin_block *)((h)->addr + (offs)))->id, (eqid), 2) ==
0)
+ (STREQLEN (((struct ntreg_hbin_block *)((h)->addr + (offs)))->id, (eqid), 2))
static size_t
block_len (hive_h *h, size_t blkoff, int *used)
diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c
index c1a3de7..8a80f66 100644
--- a/test-tool/test-tool.c
+++ b/test-tool/test-tool.c
@@ -145,7 +145,7 @@ main (int argc, char *argv[])
/* Print out any environment variables which may relate to this test. */
for (i = 0; environ[i] != NULL; ++i)
- if (strncmp (environ[i], "LIBGUESTFS_", 11) == 0)
+ if (STREQLEN (environ[i], "LIBGUESTFS_", 11))
printf ("%s\n", environ[i]);
/* Create the handle and configure it. */
--
1.6.5.2.351.g0943
From 9a8889e4d0c532b9f77af3a9cc7aae06adebfb83 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 14:30:11 +0100
Subject: [PATCH libguestfs 06/10] 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, "<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;
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 ("<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]);
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.6.5.2.351.g0943
From 539bf7e8983c53c4cf79ffa64302bef1585bec31 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 15:03:01 +0100
Subject: [PATCH libguestfs 07/10] use STREQ, not strcmp: part 2
git grep -l 'strcmp *([^=]*!= *0'|xargs \
perl -pi -e 's/\bstrcmp( *\(.*?\)) *!= *0\b/STRNEQ$1/g'
---
daemon/xattr.c | 2 +-
fish/destpaths.c | 4 ++--
fish/fish.c | 2 +-
fish/rc.c | 2 +-
src/generator.ml | 16 ++++++++--------
5 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/daemon/xattr.c b/daemon/xattr.c
index 926baf0..c218dea 100644
--- a/daemon/xattr.c
+++ b/daemon/xattr.c
@@ -403,7 +403,7 @@ do_lxattrlist (const char *path, char *const *names)
fprintf (stderr, "lxattrlist: returning: [\n");
for (k = 0; k < ret->guestfs_int_xattr_list_len; ++k) {
const guestfs_int_xattr *entry = &ret->guestfs_int_xattr_list_val[k];
- if (strcmp (entry[0].attrname, "") != 0) {
+ if (STRNEQ (entry[0].attrname, "")) {
fprintf (stderr, "ERROR: expecting empty attrname at k = %zu\n", k);
break;
}
diff --git a/fish/destpaths.c b/fish/destpaths.c
index 02e9f22..87287aa 100644
--- a/fish/destpaths.c
+++ b/fish/destpaths.c
@@ -166,8 +166,8 @@ complete_dest_paths_generator (const char *text, int state)
for (i = 0; i < dirents->len; ++i) {
int err;
- if (strcmp (dirents->val[i].name, ".") != 0 &&
- strcmp (dirents->val[i].name, "..") != 0) {
+ if (STRNEQ (dirents->val[i].name, ".") &&
+ STRNEQ (dirents->val[i].name, "..")) {
if (STREQ (dir, "/"))
err = asprintf (&p, "/%s", dirents->val[i].name);
else
diff --git a/fish/fish.c b/fish/fish.c
index 869366b..cd10296 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -762,7 +762,7 @@ cmdline (char *argv[], int optind, int argc)
params = &argv[optind];
/* Search for end of command list or ":" ... */
- while (optind < argc && strcmp (argv[optind], ":") != 0)
+ while (optind < argc && STRNEQ (argv[optind], ":"))
optind++;
if (optind == argc) {
diff --git a/fish/rc.c b/fish/rc.c
index 182c4f4..a9eb578 100644
--- a/fish/rc.c
+++ b/fish/rc.c
@@ -250,7 +250,7 @@ rc_listen (void)
goto error;
}
- if (strcmp (hello.vers, PACKAGE_VERSION) != 0) {
+ if (STRNEQ (hello.vers, PACKAGE_VERSION)) {
fprintf (stderr, _("guestfish: protocol error: version mismatch, server
version '%s' does not match client version '%s'. The two versions must
match exactly.\n"),
PACKAGE_VERSION,
hello.vers);
diff --git a/src/generator.ml b/src/generator.ml
index 917fea9..3c1ff2b 100644
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -6001,7 +6001,7 @@ and generate_one_test_body name i test_name init test =
pr " const char *expected = \"%s\";\n" (c_quote expected);
let seq, last = get_seq_last seq in
let test () =
- pr " if (strcmp (r, expected) != 0) {\n";
+ pr " if (STRNEQ (r, expected)) {\n";
pr " fprintf (stderr, \"%s: expected \\\"%%s\\\" but got
\\\"%%s\\\"\\n\", expected, r);\n" test_name;
pr " return -1;\n";
pr " }\n"
@@ -6021,7 +6021,7 @@ and generate_one_test_body name i test_name init test =
pr " }\n";
pr " {\n";
pr " const char *expected = \"%s\";\n" (c_quote
str);
- pr " if (strcmp (r[%d], expected) != 0) {\n" i;
+ pr " if (STRNEQ (r[%d], expected)) {\n" i;
pr " fprintf (stderr, \"%s: expected \\\"%%s\\\"
but got \\\"%%s\\\"\\n\", expected, r[%d]);\n" test_name i;
pr " return -1;\n";
pr " }\n";
@@ -6050,7 +6050,7 @@ and generate_one_test_body name i test_name init test =
pr " {\n";
pr " const char *expected = \"%s\";\n" (c_quote
str);
pr " r[%d][5] = 's';\n" i;
- pr " if (strcmp (r[%d], expected) != 0) {\n" i;
+ pr " if (STRNEQ (r[%d], expected)) {\n" i;
pr " fprintf (stderr, \"%s: expected \\\"%%s\\\"
but got \\\"%%s\\\"\\n\", expected, r[%d]);\n" test_name i;
pr " return -1;\n";
pr " }\n";
@@ -6174,7 +6174,7 @@ and generate_one_test_body name i test_name init test =
pr " return -1;\n";
pr " }\n"
| CompareWithString (field, expected) ->
- pr " if (strcmp (r->%s, \"%s\") != 0) {\n" field
expected;
+ pr " if (STRNEQ (r->%s, \"%s\")) {\n" field
expected;
pr " fprintf (stderr, \"%s: %s was \"%%s\",
expected \"%s\"\\n\",\n"
test_name field expected;
pr " r->%s);\n" field;
@@ -6188,7 +6188,7 @@ and generate_one_test_body name i test_name init test =
pr " return -1;\n";
pr " }\n"
| CompareFieldsStrEq (field1, field2) ->
- pr " if (strcmp (r->%s, r->%s) != 0) {\n" field1
field2;
+ pr " if (STRNEQ (r->%s, r->%s)) {\n" field1 field2;
pr " fprintf (stderr, \"%s: %s (\"%%s\") <>
%s (\"%%s\")\\n\",\n"
test_name field1 field2;
pr " r->%s, r->%s);\n" field1 field2;
@@ -6587,13 +6587,13 @@ and generate_fish_cmds () =
pr " %s = resolve_win_path (argv[%d]);\n" name i;
pr " if (%s == NULL) return -1;\n" name
| OptString name ->
- pr " %s = strcmp (argv[%d], \"\") != 0 ? argv[%d] :
NULL;\n"
+ pr " %s = STRNEQ (argv[%d], \"\") ? argv[%d] :
NULL;\n"
name i i
| FileIn name ->
- pr " %s = strcmp (argv[%d], \"-\") != 0 ? argv[%d] :
\"/dev/stdin\";\n"
+ pr " %s = STRNEQ (argv[%d], \"-\") ? argv[%d] :
\"/dev/stdin\";\n"
name i i
| FileOut name ->
- pr " %s = strcmp (argv[%d], \"-\") != 0 ? argv[%d] :
\"/dev/stdout\";\n"
+ pr " %s = STRNEQ (argv[%d], \"-\") ? argv[%d] :
\"/dev/stdout\";\n"
name i i
| StringList name | DeviceList name ->
pr " %s = parse_string_list (argv[%d]);\n" name i;
--
1.6.5.2.351.g0943
From 0c20bd8ea7092b93074ff08cae70e4cf6a06e7c5 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 22:33:36 +0100
Subject: [PATCH libguestfs 08/10] change strncasecmp() == 0 to STRCASENEQLEN()
git grep -l 'strncasecmp *([^=]*!= *0'|xargs \
perl -pi -e 's/\bstrncasecmp( *\(.*?\)) *!= *0\b/STRCASENEQLEN$1/g'
---
fish/fish.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/fish/fish.c b/fish/fish.c
index cd10296..0387eb7 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -1340,7 +1340,7 @@ resolve_win_path (const char *path)
char *ret;
size_t i;
- if (strncasecmp (path, "win:", 4) != 0) {
+ if (STRCASENEQLEN (path, "win:", 4)) {
ret = strdup (path);
if (ret == NULL)
perror ("strdup");
--
1.6.5.2.351.g0943
From c9d94984588d166bcdc077a7972a1b454678ba10 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 22:33:54 +0100
Subject: [PATCH libguestfs 09/10] change strncasecmp() == 0 to STRCASEEQLEN()
git grep -l 'strncasecmp *([^=]*== *0'|xargs \
perl -pi -e 's/\bstrncasecmp( *\(.*?\)) *== *0\b/STRCASEEQLEN$1/g'
---
fish/destpaths.c | 2 +-
fish/fish.c | 2 +-
src/generator.ml | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/fish/destpaths.c b/fish/destpaths.c
index 87287aa..c12c64a 100644
--- a/fish/destpaths.c
+++ b/fish/destpaths.c
@@ -215,7 +215,7 @@ complete_dest_paths_generator (const char *text, int state)
word = &words[index];
index++;
- if (strncasecmp (word->name, text, len) == 0) {
+ if (STRCASEEQLEN (word->name, text, len)) {
if (word->is_dir)
rl_completion_append_character = '/';
diff --git a/fish/fish.c b/fish/fish.c
index 0387eb7..3f534de 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -1350,7 +1350,7 @@ resolve_win_path (const char *path)
path += 4;
/* Drop drive letter, if it's "C:". */
- if (strncasecmp (path, "c:", 2) == 0)
+ if (STRCASEEQLEN (path, "c:", 2))
path += 2;
if (!*path) {
diff --git a/src/generator.ml b/src/generator.ml
index 3c1ff2b..4fba15f 100644
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -6772,7 +6772,7 @@ generator (const char *text, int state)
while ((name = commands[index]) != NULL) {
index++;
- if (strncasecmp (name, text, len) == 0)
+ if (STRCASEEQLEN (name, text, len))
return strdup (name);
}
--
1.6.5.2.351.g0943
From 0e1e0f10df2c45cf0c43633ce0e59a4780308e63 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 9 Nov 2009 15:05:23 +0100
Subject: [PATCH libguestfs 10/10] tests: enable strcmp-related syntax-check tests
* cfg.mk (local-checks-to-skip): Don't skip these checks:
sc_prohibit_strcmp_and_strncmp, sc_prohibit_strcmp.
---
cfg.mk | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index 134725a..0c19cc9 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -36,8 +36,6 @@ local-checks-to-skip = \
sc_prohibit_quote_without_use \
sc_prohibit_quotearg_without_use \
sc_prohibit_stat_st_blocks \
- sc_prohibit_strcmp_and_strncmp \
- sc_prohibit_strcmp \
sc_space_tab \
sc_two_space_separator_in_usage \
sc_error_message_uppercase \
--
1.6.5.2.351.g0943