From: Kay Sievers Date: Sat, 25 Oct 2008 01:00:03 +0000 (+0200) Subject: match KEY="A|B" without temporary string copy X-Git-Tag: 174~1380 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=91a75e4ad4071d9d0ce1adb5c8d8272aac379d0a;ds=inline match KEY="A|B" without temporary string copy --- diff --git a/test/udev-test.pl b/test/udev-test.pl index 9725aff5b..f630b74a9 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; }