diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-24 14:19:42 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2008-10-24 14:19:42 +0200 |
commit | db463fd3091ac9077c32ed9530b061a92d62b126 (patch) | |
tree | 58bfe89e5377ffae51687f0e2d9d2963e981c8b0 /udev | |
parent | ac218d9cc8344755654f6be34f8c60863fe2fb33 (diff) |
special-case "?*" match to skip fnmatch()
Diffstat (limited to 'udev')
-rw-r--r-- | udev/udev-rules.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/udev/udev-rules.c b/udev/udev-rules.c index 2746bd551e..5a2ae1af82 100644 --- a/udev/udev-rules.c +++ b/udev/udev-rules.c @@ -57,10 +57,11 @@ static const char *operation_str[] = { enum string_glob_type { GL_UNSET, - GL_PLAIN, - GL_GLOB, - GL_SPLIT, - GL_SPLIT_GLOB, + GL_PLAIN, /* no special chars */ + GL_GLOB, /* shell globs ?,*,[] */ + GL_SPLIT, /* multi-value A|B */ + GL_SPLIT_GLOB, /* multi-value with glob A*|B* */ + GL_SOMETHING, /* commonly used "?*" */ GL_FORMAT, }; @@ -70,6 +71,7 @@ static const char *string_glob_str[] = { [GL_GLOB] = "glob", [GL_SPLIT] = "split", [GL_SPLIT_GLOB] = "split-glob", + [GL_SOMETHING] = "split-glob", [GL_FORMAT] = "format", }; @@ -813,18 +815,22 @@ static int rule_add_token(struct rule_tmp *rule_tmp, enum token_type type, if (value != NULL) { if (type < TK_M_MAX) { /* check if we need to split or call fnmatch() while matching rules */ - int has_split = 0; - int has_glob = 0; + int has_split; + int has_glob; has_split = (strchr(value, '|') != NULL); has_glob = (strchr(value, '*') != NULL || strchr(value, '?') != NULL || strchr(value, '[') != NULL || strchr(value, ']') != NULL); - if (has_split && has_glob) + if (has_split && has_glob) { glob = GL_SPLIT_GLOB; - else if (has_split) + } else if (has_split) { glob = GL_SPLIT; - else if (has_glob) - glob = GL_GLOB; + } else if (has_glob) { + if (strcmp(value, "?*") == 0) + glob = GL_SOMETHING; + else + glob = GL_GLOB; + } } else { /* check if we need to substitute format strings for matching rules */ if (strchr(value, '%') != NULL || strchr(value, '$') != NULL) @@ -1756,6 +1762,9 @@ static int match_key(struct udev_rules *rules, struct token *token, const char * } break; } + case GL_SOMETHING: + match = (val[0] != '\0'); + break; case GL_FORMAT: case GL_UNSET: return -1; |