mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-01 21:00:10 +01:00
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 <peter.hutterer@who-t.net>
This commit is contained in:
parent
bd1fcb9c6e
commit
d724dc060b
4 changed files with 6 additions and 16 deletions
10
src/quirks.c
10
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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue