Replace strneq() with strstartswith() for variable prefixes
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 16 Jun 2020 23:37:07 +0000 (09:37 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 17 Jun 2020 07:52:00 +0000 (07:52 +0000)
Leaving in-place all those where we know the length of the prefix, but
replacing all those where we were calling strlen on the prefix.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/quirks.c
src/util-prop-parsers.c
test/litest.c
tools/libinput-record.c

index 68e0a2197aebed5c722de4ded4b067577d24421b..04b020f82a85aec3dfa978d4dd2228e447af779a 100644 (file)
@@ -978,15 +978,7 @@ out:
 
 static int
 is_data_file(const struct dirent *dir) {
-       const char *suffix = ".quirks";
-       const int slen = strlen(suffix);
-       int offset;
-
-       offset = strlen(dir->d_name) - slen;
-       if (offset <= 0)
-               return 0;
-
-       return strneq(&dir->d_name[offset], suffix, slen);
+       return strendswith(dir->d_name, ".quirks");
 }
 
 static inline bool
index 35f70b6300a11ee35fc04c9365c5aa7f49b296b2..9e076328c2a49aa9a3a74637eea37fe32bd34da2 100644 (file)
@@ -309,7 +309,7 @@ parse_evcode_string(const char *s, int *type_out, int *code_out)
                bool found = false;
 
                ARRAY_FOR_EACH(map, m) {
-                       if (!strneq(s, m->str, strlen(m->str)))
+                       if (!strstartswith(s, m->str))
                                continue;
 
                        type = m->type;
index 91589c02f97c05ab131ea01548f2bc6dac0ae273..f2e7cd70f9d4622e0e0e924b81d9a2ef5f0cff3b 100644 (file)
@@ -396,7 +396,7 @@ get_suite(const char *name)
        bool found = false;
 
        ARRAY_FOR_EACH(allowed_suites, allowed) {
-               if (strneq(name, *allowed, strlen(*allowed))) {
+               if (strstartswith(name, *allowed)) {
                        found = true;
                        break;
                }
@@ -1412,7 +1412,7 @@ litest_install_source_quirks(struct list *created_files_list,
                char dest[PATH_MAX];
                char src[PATH_MAX];
 
-               litest_assert(strneq(*q, quirksdir, strlen(quirksdir)));
+               litest_assert(strstartswith(*q, quirksdir));
                filename = &(*q)[strlen(quirksdir)];
 
                snprintf(src, sizeof(src), "%s/%s",
@@ -1795,9 +1795,7 @@ udev_wait_for_device_event(struct udev_monitor *udev_monitor,
                }
 
                udev_syspath = udev_device_get_syspath(udev_device);
-               if (udev_syspath && strneq(udev_syspath,
-                                          syspath,
-                                          strlen(syspath)))
+               if (udev_syspath && strstartswith(udev_syspath, syspath))
                        break;
 
                udev_device_unref(udev_device);
index 62626ca561d6a91116f2902bab4a9570664496ad..79715a91b3ee410a5f41172c994a54444c8d8690 100644 (file)
@@ -1733,7 +1733,7 @@ print_hid_report_descriptor(struct record_context *ctx,
           report_descriptor is available in sysfs and two devices up from
           our device. 2 digits for the event number should be enough.
           This approach won't work for /dev/input/by-id devices. */
-       if (!strneq(dev->devnode, prefix, strlen(prefix)) ||
+       if (!strstartswith(dev->devnode, prefix) ||
            strlen(dev->devnode) > strlen(prefix) + 2)
                return;