chiark / gitweb /
udev: use startswith() and streq()
[elogind.git] / src / udev / udev-event.c
index bea316c..e6f405b 100644 (file)
@@ -132,8 +132,8 @@ size_t udev_event_apply_format(struct udev_event *event, const char *src, char *
                                         goto copy;
                                 }
 
-                                for (i = 0; i < ARRAY_SIZE(map); i++) {
-                                        if (strncmp(&from[1], map[i].name, strlen(map[i].name)) == 0) {
+                                for (i = 0; i < ELEMENTSOF(map); i++) {
+                                        if (startswith(&from[1], map[i].name)) {
                                                 type = map[i].type;
                                                 from += strlen(map[i].name)+1;
                                                 goto subst;
@@ -148,7 +148,7 @@ size_t udev_event_apply_format(struct udev_event *event, const char *src, char *
                                         goto copy;
                                 }
 
-                                for (i = 0; i < ARRAY_SIZE(map); i++) {
+                                for (i = 0; i < ELEMENTSOF(map); i++) {
                                         if (from[1] == map[i].fmt) {
                                                 type = map[i].type;
                                                 from += 2;
@@ -318,46 +318,38 @@ subst:
                         if (dev_parent == NULL)
                                 break;
                         devnode = udev_device_get_devnode(dev_parent);
-                        if (devnode != NULL) {
-                                size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
-
-                                l = util_strpcpy(&s, l, &devnode[devlen]);
-                        }
+                        if (devnode != NULL)
+                                l = util_strpcpy(&s, l, devnode + strlen(TEST_PREFIX "/dev/"));
                         break;
                 }
                 case SUBST_DEVNODE:
                         if (udev_device_get_devnode(dev) != NULL)
                                 l = util_strpcpy(&s, l, udev_device_get_devnode(dev));
                         break;
-                case SUBST_NAME: {
-                        if (event->name != NULL) {
+                case SUBST_NAME:
+                        if (event->name != NULL)
                                 l = util_strpcpy(&s, l, event->name);
-                        } else if (udev_device_get_devnode(dev) != NULL) {
-                                size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
-
-                                l = util_strpcpy(&s, l, &udev_device_get_devnode(dev)[devlen]);
-                        } else {
+                        else if (udev_device_get_devnode(dev) != NULL)
+                                l = util_strpcpy(&s, l, udev_device_get_devnode(dev) + strlen(TEST_PREFIX "/dev/"));
+                        else
                                 l = util_strpcpy(&s, l, udev_device_get_sysname(dev));
-                        }
                         break;
-                }
                 case SUBST_LINKS: {
-                        size_t devlen = strlen(udev_get_dev_path(event->udev))+1;
                         struct udev_list_entry *list_entry;
 
                         list_entry = udev_device_get_devlinks_list_entry(dev);
                         if (list_entry == NULL)
                                 break;
-                        l = util_strpcpy(&s, l, &udev_list_entry_get_name(list_entry)[devlen]);
+                        l = util_strpcpy(&s, l, udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"));
                         udev_list_entry_foreach(list_entry, udev_list_entry_get_next(list_entry))
-                                l = util_strpcpyl(&s, l, " ", &udev_list_entry_get_name(list_entry)[devlen], NULL);
+                                l = util_strpcpyl(&s, l, " ", udev_list_entry_get_name(list_entry) + strlen(TEST_PREFIX "/dev/"), NULL);
                         break;
                 }
                 case SUBST_ROOT:
-                        l = util_strpcpy(&s, l, udev_get_dev_path(event->udev));
+                        l = util_strpcpy(&s, l, TEST_PREFIX "/dev");
                         break;
                 case SUBST_SYS:
-                        l = util_strpcpy(&s, l, udev_get_sys_path(event->udev));
+                        l = util_strpcpy(&s, l, TEST_PREFIX "/sys");
                         break;
                 case SUBST_ENV:
                         if (attr == NULL) {
@@ -486,7 +478,7 @@ static void spawn_read(struct udev_event *event,
                         timeout = -1;
                 }
 
-                fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), timeout);
+                fdcount = epoll_wait(fd_ep, ev, ELEMENTSOF(ev), timeout);
                 if (fdcount < 0) {
                         if (errno == EINTR)
                                 continue;