diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-25 03:00:03 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-25 03:00:03 +0200 |
commit | 91a75e4ad4071d9d0ce1adb5c8d8272aac379d0a (patch) | |
tree | 115c3a7922255abcf94cd42c02bb927ba605baf5 /udev/udev-rules.c | |
parent | b62557daff59dbe3096dc31ac1f42a20ff6a9f92 (diff) |
match KEY="A|B" without temporary string copy
Diffstat (limited to 'udev/udev-rules.c')
-rw-r--r-- | udev/udev-rules.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/udev/udev-rules.c b/udev/udev-rules.c index 0643811d7a..8c0e1d961b 100644 --- a/udev/udev-rules.c +++ b/udev/udev-rules.c @@ -1726,21 +1726,26 @@ static int match_key(struct udev_rules *rules, struct token *token, const char * break; case GL_SPLIT: { - char value[UTIL_PATH_SIZE]; + const char *split; + size_t len; - util_strlcpy(value, &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; } |