change strncmp() == 0 to STREQLEN()
authorJim Meyering <meyering@redhat.com>
Mon, 9 Nov 2009 13:26:21 +0000 (14:26 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 9 Nov 2009 21:34:16 +0000 (22:34 +0100)
git grep -l 'strncmp *([^=]*== *0'|xargs \
  perl -pi -e 's/\bstrncmp( *\(.*?\)) *== *0\b/STREQLEN$1/g'

13 files changed:
daemon/daemon.h
daemon/devsparts.c
daemon/ext2.c
daemon/file.c
daemon/guestfsd.c
daemon/mount.c
daemon/upload.c
examples/to-xml.c
fish/destpaths.c
fish/edit.c
fish/tilde.c
hivex/hivex.c
test-tool/test-tool.c

index 1cdb480..ac68479 100644 (file)
@@ -184,7 +184,7 @@ extern void reply (xdrproc_t xdrp, char *ret);
  */
 #define REQUIRE_ROOT_OR_RESOLVE_DEVICE(path,fail_stmt)                 \
   do {                                                                 \
  */
 #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);                                           \
       RESOLVE_DEVICE ((path), fail_stmt);                              \
     else {                                                             \
       NEED_ROOT (fail_stmt);                                           \
index 76852cc..60e7aa8 100644 (file)
@@ -53,10 +53,10 @@ foreach_block_device (block_dev_func_t func)
     struct dirent *d = readdir(dir);
     if(NULL == d) break;
 
     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);
 
       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) {
   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);
 
       char part[256];
       snprintf (part, sizeof part, "/dev/%s", d->d_name);
 
index 0021a06..14cbb3c 100644 (file)
@@ -48,7 +48,7 @@ do_tune2fs_l (const char *device)
   p = out;
 
   /* Discard the first line if it contains "tune2fs ...". */
   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 {
     p = strchr (p, '\n');
     if (p) p++;
     else {
index 7854ade..62de116 100644 (file)
@@ -430,7 +430,7 @@ do_file (const char *path)
   char *buf;
   int len;
 
   char *buf;
   int len;
 
-  if (strncmp (path, "/dev/", 5) == 0)
+  if (STREQLEN (path, "/dev/", 5))
     buf = (char *) path;
   else {
     buf = sysroot_path (path);
     buf = (char *) path;
   else {
     buf = sysroot_path (path);
index 61a6236..5789fed 100644 (file)
@@ -226,7 +226,7 @@ main (int argc, char *argv[])
   /* Connect to vmchannel. */
   int sock = -1;
 
   /* 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;
     /* Resolve the hostname. */
     struct addrinfo *res, *rr;
     struct addrinfo hints;
index 463e789..5a27cea 100644 (file)
@@ -112,7 +112,7 @@ do_umount (const char *pathordevice)
   char *buf;
   int is_dev;
 
   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) {
   buf = is_dev ? strdup (pathordevice)
                : sysroot_path (pathordevice);
   if (buf == NULL) {
index da86bd6..7b2ccea 100644 (file)
@@ -40,7 +40,7 @@ do_upload (const char *filename)
 {
   int err, fd, r, is_dev;
 
 {
   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 ();
   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];
 
   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);
 
   if (!is_dev) CHROOT_IN;
   fd = open (filename, O_RDONLY);
index f48d1ca..4317619 100644 (file)
@@ -87,8 +87,8 @@ main (int argc, char *argv[])
     int len = strlen (vgs[i]);
     int j;
     for (j = 0; lvs[j] != NULL; ++j) {
     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);
           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);
     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");
     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. */
   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);
       int64_t size;
       CALL (size = guestfs_blockdev_getsize64 (g, parts[i]), -1);
       printf ("<partition dev=\"%s\" size=\"%" PRIi64 "\">\n", parts[i], size);
index 1e42ae8..9a3da82 100644 (file)
@@ -133,7 +133,7 @@ complete_dest_paths_generator (const char *text, int state)
   } while (0)
 
     /* Is it a device? */
   } 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;
       /* Get a list of everything that can possibly begin with /dev/ */
       strs = guestfs_list_devices (g);
       APPEND_STRS_AND_FREE;
index d30b3ca..3fc41fb 100644 (file)
@@ -149,7 +149,7 @@ do_edit (const char *cmd, int argc, char *argv[])
   unlink (filename);
 
   /* Changed? */
   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;
     free (content);
     free (content_new);
     return 0;
index 1c52d3e..64b5b39 100644 (file)
@@ -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 &&
   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;
   }
 
       return pw->pw_dir;
   }
 
index 8ea2c2b..4b0deeb 100644 (file)
@@ -143,7 +143,7 @@ struct ntreg_hbin_block {
 } __attribute__((__packed__));
 
 #define BLOCK_ID_EQ(h,offs,eqid) \
 } __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)
 
 static size_t
 block_len (hive_h *h, size_t blkoff, int *used)
index c1a3de7..8a80f66 100644 (file)
@@ -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)
 
   /* 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. */
       printf ("%s\n", environ[i]);
 
   /* Create the handle and configure it. */