From: Peter Hutterer Date: Tue, 16 Jun 2020 23:37:07 +0000 (+1000) Subject: Replace strneq() with strstartswith() for variable prefixes X-Git-Tag: 1.15.901~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d724dc060b190bc59eff9c3caf5eee08083d4db2;p=platform%2Fupstream%2Flibinput.git Replace strneq() with strstartswith() for variable prefixes 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 --- diff --git a/src/quirks.c b/src/quirks.c index 68e0a219..04b020f8 100644 --- a/src/quirks.c +++ b/src/quirks.c @@ -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 diff --git a/src/util-prop-parsers.c b/src/util-prop-parsers.c index 35f70b63..9e076328 100644 --- a/src/util-prop-parsers.c +++ b/src/util-prop-parsers.c @@ -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; diff --git a/test/litest.c b/test/litest.c index 91589c02..f2e7cd70 100644 --- a/test/litest.c +++ b/test/litest.c @@ -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); diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 62626ca5..79715a91 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -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;