From 9fe3f9a9389bb06cf645d33cbb2b45e1f63d737c Mon Sep 17 00:00:00 2001 From: "kay.sievers@vrfy.org" Date: Wed, 3 Mar 2004 18:16:35 -0800 Subject: [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. --- udev-remove.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) (limited to 'udev-remove.c') diff --git a/udev-remove.c b/udev-remove.c index dcd460bedc..93adcc7806 100644 --- a/udev-remove.c +++ b/udev-remove.c @@ -67,12 +67,12 @@ static int delete_path(char *path) static int delete_node(struct udevice *dev) { - char filename[255]; - char partitionname[255]; - char *symlinks; - char *linkname; + char filename[NAME_SIZE]; + char linkname[NAME_SIZE]; + char partitionname[NAME_SIZE]; int retval; int i; + int pos, len; strfieldcpy(filename, udev_root); strfieldcat(filename, dev->name); @@ -101,28 +101,22 @@ static int delete_node(struct udevice *dev) if (strchr(dev->name, '/')) delete_path(filename); - if (dev->symlink[0] != '\0') { - symlinks = dev->symlink; - while (1) { - linkname = strsep(&symlinks, " "); - if (linkname == NULL) - break; - - strfieldcpy(filename, udev_root); - strfieldcat(filename, linkname); - - dbg("unlinking symlink '%s'", filename); - retval = unlink(filename); - if (errno == ENOENT) - retval = 0; - if (retval) { - dbg("unlink(%s) failed with error '%s'", - filename, strerror(errno)); - return retval; - } - if (strchr(dev->symlink, '/')) { - delete_path(filename); - } + foreach_strpart(dev->symlink, " ", pos, len) { + strnfieldcpy(linkname, dev->symlink + pos, len+1); + strfieldcpy(filename, udev_root); + strfieldcat(filename, linkname); + + dbg("unlinking symlink '%s'", filename); + retval = unlink(filename); + if (errno == ENOENT) + retval = 0; + if (retval) { + dbg("unlink(%s) failed with error '%s'", + filename, strerror(errno)); + return retval; + } + if (strchr(dev->symlink, '/')) { + delete_path(filename); } } -- cgit v1.2.3-54-g00ecf