From 3e70b34eed5a48640e20fbf6dcba774aaace1f3c Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 9 Nov 2009 14:26:21 +0100 Subject: [PATCH] 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 ("\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 ("\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 ("\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.8.3.1