diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2004-03-03 18:16:35 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:35:08 -0700 |
commit | 9fe3f9a9389bb06cf645d33cbb2b45e1f63d737c (patch) | |
tree | b433b3a99180227203027ec80f825ba94ac59869 /udevdb.c | |
parent | 88ed4bbe5605f6fe17993c5b81709f4d12812b9a (diff) |
[PATCH] cleanup mult field string handling
Here I try to cleanup our various multifield iteration over the strings.
Inspired by our nice list.h we now have a macro to iterate over the string
and process the parts of it:
It makes the code more readable and we don't change the string while we
process it like the former strsep() does.
Example:
foreach_strpart(dev->symlink, " ", pos, len) {
if (strncmp(&dev->symlink[pos], find_name, len) != 0)
continue;
...
}
For the callout part selector %c{2} we separate now not only by space but
also newline and return characters, cause some programs may give multiline
values back. A possible RESULT match must contain wildcards for these
characters.
Also a bug in the recent udevinfo symlink query feature is fixed.
Diffstat (limited to 'udevdb.c')
-rw-r--r-- | udevdb.c | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -179,7 +179,8 @@ static int find_found; static int find_device_by_name(char *path, struct udevice *dev) { - int l, i, j; + int pos, len; + if (strncmp(dev->name, find_name, sizeof(dev->name)) == 0) { memcpy(find_dev, dev, sizeof(struct udevice)); strnfieldcpy(find_path, path, NAME_SIZE); @@ -188,20 +189,18 @@ static int find_device_by_name(char *path, struct udevice *dev) return 1; } /* look for matching symlink*/ - l = strlen(dev->symlink); - if (!l) - return 0; - i = j = 0; - do { - j = strcspn(&dev->symlink[i], " "); - if (j && strncmp(&dev->symlink[i], find_name, j) == 0) { - memcpy(find_dev, dev, sizeof(struct udevice)); - strnfieldcpy(find_path, path, NAME_SIZE); - find_found = 1; - return 1; - } - i = i + j + 1; - } while (i < l); + foreach_strpart(dev->symlink, " ", pos, len) { + if (strncmp(&dev->symlink[pos], find_name, len) != 0) + continue; + + if (len != strlen(find_name)) + continue; + + memcpy(find_dev, dev, sizeof(struct udevice)); + strnfieldcpy(find_path, path, NAME_SIZE); + find_found = 1; + return 1; + } return 0; } |