From 91a75e4ad4071d9d0ce1adb5c8d8272aac379d0a Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sat, 25 Oct 2008 03:00:03 +0200 Subject: [PATCH] match KEY="A|B" without temporary string copy --- test/udev-test.pl | 25 +++++++++++++++++++++++++ udev/udev-rules.c | 31 ++++++++++++++++++------------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/test/udev-test.pl b/test/udev-test.pl index 9725aff5..f630b74a 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -1448,6 +1448,31 @@ EOF KERNEL=="dontknow*|*nothing", NAME="nomatch" KERNEL=="ttyACM*", NAME="before" KERNEL=="dontknow*|ttyACM*|nothing*", NAME="right" +EOF + }, + { + desc => "test multi matches 3", + subsys => "tty", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "right", + rules => < "test multi matches 4", + subsys => "tty", + devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0", + exp_name => "right", + rules => <buf[token->key.value_off], sizeof(value)); - key_value = value; - while (key_value != NULL) { - pos = strchr(key_value, '|'); - if (pos != NULL) { - pos[0] = '\0'; - pos = &pos[1]; - } - dbg(rules->udev, "match %s '%s' <-> '%s'\n", token_str[token->type], key_value, val); - match = (strcmp(key_value, val) == 0); - if (match) + split = &rules->buf[token->key.value_off]; + len = strlen(val); + while (1) { + const char *next; + + next = strchr(split, '|'); + if (next != NULL) { + size_t matchlen = (size_t)(next - split); + + match = (matchlen == len && strncmp(split, val, matchlen) == 0); + if (match) + break; + } else { + match = (strcmp(split, val) == 0); break; - key_value = pos; + } + split = &next[1]; } break; } -- 2.39.5