chiark / gitweb /
use streq instead of strcmp
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Wed, 13 Feb 2013 17:13:22 +0000 (18:13 +0100)
committerThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Wed, 13 Feb 2013 17:14:20 +0000 (18:14 +0100)
22 files changed:
src/boot/boot-loader.c
src/journal/test-journal-syslog.c
src/libudev/libudev-monitor.c
src/libudev/libudev-queue.c
src/libudev/libudev-util.c
src/libudev/libudev.c
src/test/test-udev.c
src/udev/accelerometer/accelerometer.c
src/udev/collect/collect.c
src/udev/scsi_id/scsi_id.c
src/udev/udev-builtin-kmod.c
src/udev/udev-builtin-net_id.c
src/udev/udev-builtin-path_id.c
src/udev/udev-builtin-usb_id.c
src/udev/udev-builtin.c
src/udev/udev-event.c
src/udev/udev-node.c
src/udev/udevadm-info.c
src/udev/udevadm-test.c
src/udev/udevadm-trigger.c
src/udev/udevadm.c
src/udev/udevd.c

index d1a8b03..d44fdb3 100644 (file)
@@ -121,7 +121,7 @@ int boot_loader_find_active_entry(struct boot_info *info, const char *loader_act
                 return -ENOMEM;
 
         for (i = 0; i < info->loader_entries_count; i++) {
-                if (strcmp(fn, info->loader_entries[i].path) == 0) {
+                if (streq(fn, info->loader_entries[i].path)) {
                         info->loader_entry_active = i;
                         break;
                 }
index 3ae8633..5cf9407 100644 (file)
@@ -31,8 +31,8 @@ static void test_syslog_parse_identifier(const char* str,
         ret2 = syslog_parse_identifier(&buf, &ident2, &pid2);
 
         assert(ret == ret2);
-        assert(ident==ident2 || !strcmp(ident, ident2));
-        assert(pid==pid2 || !strcmp(pid, pid2));
+        assert(ident==ident2 || streq(ident, ident2));
+        assert(pid==pid2 || streq(pid, pid2));
 }
 
 int main(void) {
index b02ea88..0212792 100644 (file)
@@ -115,9 +115,9 @@ struct udev_monitor *udev_monitor_new_from_netlink_fd(struct udev *udev, const c
 
         if (name == NULL)
                 group = UDEV_MONITOR_NONE;
-        else if (strcmp(name, "udev") == 0)
+        else if (streq(name, "udev"))
                 group = UDEV_MONITOR_UDEV;
-        else if (strcmp(name, "kernel") == 0)
+        else if (streq(name, "kernel"))
                 group = UDEV_MONITOR_KERNEL;
         else
                 return NULL;
@@ -467,7 +467,7 @@ static int passes_filter(struct udev_monitor *udev_monitor, struct udev_device *
                 const char *devtype;
                 const char *ddevtype;
 
-                if (strcmp(dsubsys, subsys) != 0)
+                if (!streq(dsubsys, subsys))
                         continue;
 
                 devtype = udev_list_entry_get_value(list_entry);
@@ -476,7 +476,7 @@ static int passes_filter(struct udev_monitor *udev_monitor, struct udev_device *
                 ddevtype = udev_device_get_devtype(udev_device);
                 if (ddevtype == NULL)
                         continue;
-                if (strcmp(ddevtype, devtype) == 0)
+                if (streq(ddevtype, devtype))
                         goto tag;
         }
         return 0;
index bfb4807..0dd2031 100644 (file)
@@ -467,7 +467,7 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu
                         udev_list_entry_add(&udev_queue->queue_list, syspath, seqnum_str);
                 } else {
                         udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_queue->queue_list)) {
-                                if (strcmp(seqnum_str, udev_list_entry_get_value(list_entry)) == 0) {
+                                if (streq(seqnum_str, udev_list_entry_get_value(list_entry))) {
                                         udev_list_entry_delete(list_entry);
                                         break;
                                 }
index 2eb7907..62b7e56 100644 (file)
@@ -83,7 +83,7 @@ uid_t util_lookup_user(struct udev *udev, const char *user)
         size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
         char *buf = alloca(buflen);
 
-        if (strcmp(user, "root") == 0)
+        if (streq(user, "root"))
                 return 0;
         uid = strtoul(user, &endptr, 10);
         if (endptr[0] == '\0')
@@ -108,7 +108,7 @@ gid_t util_lookup_group(struct udev *udev, const char *group)
         size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
         char *buf = NULL;
 
-        if (strcmp(group, "root") == 0)
+        if (streq(group, "root"))
                 return 0;
         gid = strtoul(group, &endptr, 10);
         if (endptr[0] == '\0')
index d860ebc..208039a 100644 (file)
@@ -191,7 +191,7 @@ _public_ struct udev *udev_new(void)
                                 val++;
                         }
 
-                        if (strcmp(key, "udev_log") == 0) {
+                        if (streq(key, "udev_log")) {
                                 udev_set_log_priority(udev, util_log_priority(val));
                                 continue;
                         }
index aee87f7..52b61b4 100644 (file)
@@ -140,12 +140,12 @@ int main(int argc, char *argv[])
         if (udev_device_get_devnode(dev) != NULL) {
                 mode_t mode = 0600;
 
-                if (strcmp(udev_device_get_subsystem(dev), "block") == 0)
+                if (streq(udev_device_get_subsystem(dev), "block"))
                         mode |= S_IFBLK;
                 else
                         mode |= S_IFCHR;
 
-                if (strcmp(action, "remove") != 0) {
+                if (!streq(action, "remove")) {
                         mkdir_parents_label(udev_device_get_devnode(dev), 0755);
                         mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev));
                 } else {
index 2fea388..f50db71 100644 (file)
@@ -122,7 +122,7 @@ string_to_orientation (const char *orientation)
         if (orientation == NULL)
                 return ORIENTATION_UNDEFINED;
         for (i = 0; orientations[i] != NULL; i++) {
-                if (strcmp (orientation, orientations[i]) == 0)
+                if (streq (orientation, orientations[i]))
                         return i;
         }
         return ORIENTATION_UNDEFINED;
index f594814..7850cfa 100644 (file)
@@ -213,7 +213,7 @@ static void invite(char *us)
         udev_list_node_foreach(him_node, &bunch) {
                 struct _mate *him = node_to_mate(him_node);
 
-                if (!strcmp(him->name, us)) {
+                if (streq(him->name, us)) {
                         him->state = STATE_CONFIRMED;
                         who = him;
                 }
@@ -241,7 +241,7 @@ static void reject(char *us)
         udev_list_node_foreach(him_node, &bunch) {
                 struct _mate *him = node_to_mate(him_node);
 
-                if (!strcmp(him->name, us)) {
+                if (streq(him->name, us)) {
                         him->state = STATE_NONE;
                         who = him;
                 }
@@ -434,7 +434,7 @@ int main(int argc, char **argv)
                 udev_list_node_foreach(him_node, &bunch) {
                         struct _mate *him = node_to_mate(him_node);
 
-                        if (!strcmp(him->name, argv[i]))
+                        if (streq(him->name, argv[i]))
                                 who = him;
                 }
                 if (!who) {
index dcf03ee..ab7c54c 100644 (file)
@@ -372,11 +372,11 @@ static int set_options(struct udev *udev,
                         exit(0);
 
                 case 'p':
-                        if (strcmp(optarg, "0x80") == 0) {
+                        if (streq(optarg, "0x80")) {
                                 default_page_code = PAGE_80;
-                        } else if (strcmp(optarg, "0x83") == 0) {
+                        } else if (streq(optarg, "0x83")) {
                                 default_page_code = PAGE_83;
-                        } else if (strcmp(optarg, "pre-spc3-83") == 0) {
+                        } else if (streq(optarg, "pre-spc3-83")) {
                                 default_page_code = PAGE_83_PRE_SPC3;
                         } else {
                                 log_error("Unknown page code '%s'\n", optarg);
@@ -449,11 +449,11 @@ static int per_dev_options(struct udev *udev,
                         break;
 
                 case 'p':
-                        if (strcmp(optarg, "0x80") == 0) {
+                        if (streq(optarg, "0x80")) {
                                 *page_code = PAGE_80;
-                        } else if (strcmp(optarg, "0x83") == 0) {
+                        } else if (streq(optarg, "0x83")) {
                                 *page_code = PAGE_83;
-                        } else if (strcmp(optarg, "pre-spc3-83") == 0) {
+                        } else if (streq(optarg, "pre-spc3-83")) {
                                 *page_code = PAGE_83_PRE_SPC3;
                         } else {
                                 log_error("Unknown page code '%s'\n", optarg);
index 17aca29..fc28121 100644 (file)
@@ -78,7 +78,7 @@ static int builtin_kmod(struct udev_device *dev, int argc, char *argv[], bool te
         if (!ctx)
                 return 0;
 
-        if (argc < 3 || strcmp(argv[1], "load")) {
+        if (argc < 3 || !streq(argv[1], "load")) {
                 log_error("expect: %s load <module>\n", argv[0]);
                 return EXIT_FAILURE;
         }
index c55c34d..57674bf 100644 (file)
@@ -413,7 +413,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
         p = udev_device_get_sysattr_value(dev, "iflink");
         if (!p)
                 return EXIT_FAILURE;
-        if (strcmp(s, p) != 0)
+        if (!streq(s, p))
                 return 0;
 
         devtype = udev_device_get_devtype(dev);
index d6b3736..da02731 100644 (file)
@@ -83,7 +83,7 @@ static struct udev_device *skip_subsystem(struct udev_device *dev, const char *s
                 const char *subsystem;
 
                 subsystem = udev_device_get_subsystem(parent);
-                if (subsystem == NULL || strcmp(subsystem, subsys) != 0)
+                if (subsystem == NULL || !streq(subsystem, subsys))
                         break;
                 dev = parent;
                 parent = udev_device_get_parent(parent);
@@ -345,7 +345,7 @@ static struct udev_device *handle_scsi(struct udev_device *parent, char **path)
         const char *id;
 
         devtype = udev_device_get_devtype(parent);
-        if (devtype == NULL || strcmp(devtype, "scsi_device") != 0)
+        if (devtype == NULL || !streq(devtype, "scsi_device"))
                 return parent;
 
         /* firewire */
@@ -438,7 +438,7 @@ static struct udev_device *handle_usb(struct udev_device *parent, char **path)
         devtype = udev_device_get_devtype(parent);
         if (devtype == NULL)
                 return parent;
-        if (strcmp(devtype, "usb_interface") != 0 && strcmp(devtype, "usb_device") != 0)
+        if (!streq(devtype, "usb_interface") && !streq(devtype, "usb_device"))
                 return parent;
 
         str = udev_device_get_sysname(parent);
@@ -498,37 +498,37 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
                 subsys = udev_device_get_subsystem(parent);
                 if (subsys == NULL) {
                         ;
-                } else if (strcmp(subsys, "scsi_tape") == 0) {
+                } else if (streq(subsys, "scsi_tape")) {
                         handle_scsi_tape(parent, &path);
-                } else if (strcmp(subsys, "scsi") == 0) {
+                } else if (streq(subsys, "scsi")) {
                         parent = handle_scsi(parent, &path);
                         some_transport = true;
-                } else if (strcmp(subsys, "cciss") == 0) {
+                } else if (streq(subsys, "cciss")) {
                         parent = handle_cciss(parent, &path);
                         some_transport = true;
-                } else if (strcmp(subsys, "usb") == 0) {
+                } else if (streq(subsys, "usb")) {
                         parent = handle_usb(parent, &path);
                         some_transport = true;
-                } else if (strcmp(subsys, "serio") == 0) {
+                } else if (streq(subsys, "serio")) {
                         path_prepend(&path, "serio-%s", udev_device_get_sysnum(parent));
                         parent = skip_subsystem(parent, "serio");
-                } else if (strcmp(subsys, "pci") == 0) {
+                } else if (streq(subsys, "pci")) {
                         path_prepend(&path, "pci-%s", udev_device_get_sysname(parent));
                         parent = skip_subsystem(parent, "pci");
-                } else if (strcmp(subsys, "platform") == 0) {
+                } else if (streq(subsys, "platform")) {
                         path_prepend(&path, "platform-%s", udev_device_get_sysname(parent));
                         parent = skip_subsystem(parent, "platform");
                         some_transport = true;
-                } else if (strcmp(subsys, "acpi") == 0) {
+                } else if (streq(subsys, "acpi")) {
                         path_prepend(&path, "acpi-%s", udev_device_get_sysname(parent));
                         parent = skip_subsystem(parent, "acpi");
-                } else if (strcmp(subsys, "xen") == 0) {
+                } else if (streq(subsys, "xen")) {
                         path_prepend(&path, "xen-%s", udev_device_get_sysname(parent));
                         parent = skip_subsystem(parent, "xen");
-                } else if (strcmp(subsys, "virtio") == 0) {
+                } else if (streq(subsys, "virtio")) {
                         path_prepend(&path, "virtio-pci-%s", udev_device_get_sysname(parent));
                         parent = skip_subsystem(parent, "virtio");
-                } else if (strcmp(subsys, "scm") == 0) {
+                } else if (streq(subsys, "scm")) {
                         path_prepend(&path, "scm-%s", udev_device_get_sysname(parent));
                         parent = skip_subsystem(parent, "scm");
                 }
index 7ce401d..01e42ca 100644 (file)
@@ -273,7 +273,7 @@ static int builtin_usb_id(struct udev_device *dev, int argc, char *argv[], bool
         instance_str[0] = '\0';
 
         /* shortcut, if we are called directly for a "usb_device" type */
-        if (udev_device_get_devtype(dev) != NULL && strcmp(udev_device_get_devtype(dev), "usb_device") == 0) {
+        if (udev_device_get_devtype(dev) != NULL && streq(udev_device_get_devtype(dev), "usb_device")) {
                 dev_if_packed_info(dev, packed_if_str, sizeof(packed_if_str));
                 dev_usb = dev;
                 goto fallback;
index 0651ae2..57d75a1 100644 (file)
@@ -115,7 +115,7 @@ enum udev_builtin_cmd udev_builtin_lookup(const char *command)
         if (pos)
                 pos[0] = '\0';
         for (i = 0; i < ELEMENTSOF(builtins); i++)
-                if (strcmp(builtins[i]->name, name) == 0)
+                if (streq(builtins[i]->name, name))
                         return i;
         return UDEV_BUILTIN_MAX;
 }
index ef9fc61..efd9b6d 100644 (file)
@@ -784,7 +784,7 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
         if (udev_device_get_subsystem(dev) == NULL)
                 return -1;
 
-        if (strcmp(udev_device_get_action(dev), "remove") == 0) {
+        if (streq(udev_device_get_action(dev), "remove")) {
                 udev_device_read_db(dev, NULL);
                 udev_device_delete_db(dev);
                 udev_device_tag_index(dev, NULL, false);
@@ -812,8 +812,8 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
                 udev_rules_apply_to_event(rules, event, sigmask);
 
                 /* rename a new network interface, if needed */
-                if (udev_device_get_ifindex(dev) > 0 && strcmp(udev_device_get_action(dev), "add") == 0 &&
-                    event->name != NULL && strcmp(event->name, udev_device_get_sysname(dev)) != 0) {
+                if (udev_device_get_ifindex(dev) > 0 && streq(udev_device_get_action(dev), "add") &&
+                    event->name != NULL && !streq(event->name, udev_device_get_sysname(dev))) {
                         char syspath[UTIL_PATH_SIZE];
                         char *pos;
 
index 363cee1..1148a15 100644 (file)
@@ -74,7 +74,7 @@ static int node_symlink(struct udev_device *dev, const char *node, const char *s
                         len = readlink(slink, buf, sizeof(buf));
                         if (len > 0 && len < (int)sizeof(buf)) {
                                 buf[len] = '\0';
-                                if (strcmp(target, buf) == 0) {
+                                if (streq(target, buf)) {
                                         log_debug("preserve already existing symlink '%s' to '%s'\n", slink, target);
                                         label_fix(slink, true, false);
                                         utimensat(AT_FDCWD, slink, NULL, AT_SYMLINK_NOFOLLOW);
@@ -154,7 +154,7 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons
                 log_debug("found '%s' claiming '%s'\n", dent->d_name, stackdir);
 
                 /* did we find ourself? */
-                if (strcmp(dent->d_name, udev_device_get_id_filename(dev)) == 0)
+                if (streq(dent->d_name, udev_device_get_id_filename(dev)))
                         continue;
 
                 dev_db = udev_device_new_from_device_id(udev, dent->d_name);
@@ -238,7 +238,7 @@ void udev_node_update_old_links(struct udev_device *dev, struct udev_device *dev
                 udev_list_entry_foreach(list_entry_current, udev_device_get_devlinks_list_entry(dev)) {
                         const char *name_current = udev_list_entry_get_name(list_entry_current);
 
-                        if (strcmp(name, name_current) == 0) {
+                        if (streq(name, name_current)) {
                                 found = 1;
                                 break;
                         }
@@ -259,7 +259,7 @@ static int node_permissions_apply(struct udev_device *dev, bool apply, mode_t mo
         struct stat stats;
         int err = 0;
 
-        if (strcmp(udev_device_get_subsystem(dev), "block") == 0)
+        if (streq(udev_device_get_subsystem(dev), "block"))
                 mode |= S_IFBLK;
         else
                 mode |= S_IFCHR;
@@ -307,7 +307,7 @@ void udev_node_add(struct udev_device *dev, bool apply, mode_t mode, uid_t uid,
 
         /* always add /dev/{block,char}/$major:$minor */
         snprintf(filename, sizeof(filename), "/dev/%s/%u:%u",
-                 strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char",
+                 streq(udev_device_get_subsystem(dev), "block") ? "block" : "char",
                  major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)));
         node_symlink(dev, udev_device_get_devnode(dev), filename);
 
@@ -327,7 +327,7 @@ void udev_node_remove(struct udev_device *dev)
 
         /* remove /dev/{block,char}/$major:$minor */
         snprintf(filename, sizeof(filename), "/dev/%s/%u:%u",
-                 strcmp(udev_device_get_subsystem(dev), "block") == 0 ? "block" : "char",
+                 streq(udev_device_get_subsystem(dev), "block") ? "block" : "char",
                  major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)));
         unlink(filename);
 }
index d6f8286..0f4565e 100644 (file)
@@ -45,7 +45,7 @@ static bool skip_attribute(const char *name)
         unsigned int i;
 
         for (i = 0; i < ELEMENTSOF(skip); i++)
-                if (strcmp(name, skip[i]) == 0)
+                if (streq(name, skip[i]))
                         return true;
         return false;
 }
@@ -393,15 +393,15 @@ static int uinfo(struct udev *udev, int argc, char *argv[])
                         break;
                 case 'q':
                         action = ACTION_QUERY;
-                        if (strcmp(optarg, "property") == 0 || strcmp(optarg, "env") == 0) {
+                        if (streq(optarg, "property") || streq(optarg, "env")) {
                                 query = QUERY_PROPERTY;
-                        } else if (strcmp(optarg, "name") == 0) {
+                        } else if (streq(optarg, "name")) {
                                 query = QUERY_NAME;
-                        } else if (strcmp(optarg, "symlink") == 0) {
+                        } else if (streq(optarg, "symlink")) {
                                 query = QUERY_SYMLINK;
-                        } else if (strcmp(optarg, "path") == 0) {
+                        } else if (streq(optarg, "path")) {
                                 query = QUERY_PATH;
-                        } else if (strcmp(optarg, "all") == 0) {
+                        } else if (streq(optarg, "all")) {
                                 query = QUERY_ALL;
                         } else {
                                 fprintf(stderr, "unknown query type\n");
index f22a2c3..df1409b 100644 (file)
@@ -66,11 +66,11 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
                         action = optarg;
                         break;
                 case 'N':
-                        if (strcmp (optarg, "early") == 0) {
+                        if (streq (optarg, "early")) {
                                 resolve_names = 1;
-                        } else if (strcmp (optarg, "late") == 0) {
+                        } else if (streq (optarg, "late")) {
                                 resolve_names = 0;
-                        } else if (strcmp (optarg, "never") == 0) {
+                        } else if (streq (optarg, "never")) {
                                 resolve_names = -1;
                         } else {
                                 fprintf(stderr, "resolve-names must be early, late or never\n");
index 4d96a78..9624c66 100644 (file)
@@ -122,9 +122,9 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
                         dry_run = 1;
                         break;
                 case 't':
-                        if (strcmp(optarg, "devices") == 0) {
+                        if (streq(optarg, "devices")) {
                                 device_type = TYPE_DEVICES;
-                        } else if (strcmp(optarg, "subsystems") == 0) {
+                        } else if (streq(optarg, "subsystems")) {
                                 device_type = TYPE_SUBSYSTEMS;
                         } else {
                                 log_error("unknown type --type=%s\n", optarg);
index 53419ff..e14b3ca 100644 (file)
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
 
         if (command != NULL)
                 for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) {
-                        if (strcmp(udevadm_cmds[i]->name, command) == 0) {
+                        if (streq(udevadm_cmds[i]->name, command)) {
                                 argc -= optind;
                                 argv += optind;
                                 /* we need '0' here to reset the internal state */
index 9f18462..088a89f 100644 (file)
@@ -499,7 +499,7 @@ static bool is_devpath_busy(struct event *event)
                         return true;
 
                 /* check our old name */
-                if (event->devpath_old != NULL && strcmp(loop_event->devpath, event->devpath_old) == 0) {
+                if (event->devpath_old != NULL && streq(loop_event->devpath, event->devpath_old)) {
                         event->delaying_seqnum = loop_event->seqnum;
                         return true;
                 }
@@ -1117,11 +1117,11 @@ int main(int argc, char *argv[])
                         udev_set_log_priority(udev, LOG_DEBUG);
                         break;
                 case 'N':
-                        if (strcmp (optarg, "early") == 0) {
+                        if (streq(optarg, "early")) {
                                 resolve_names = 1;
-                        } else if (strcmp (optarg, "late") == 0) {
+                        } else if (streq(optarg, "late")) {
                                 resolve_names = 0;
-                        } else if (strcmp (optarg, "never") == 0) {
+                        } else if (streq(optarg, "never")) {
                                 resolve_names = -1;
                         } else {
                                 fprintf(stderr, "resolve-names must be early, late or never\n");