summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--namedev.c39
-rw-r--r--udev_add.c4
-rw-r--r--udev_remove.c4
-rw-r--r--udev_utils.h20
4 files changed, 26 insertions, 41 deletions
diff --git a/namedev.c b/namedev.c
index 91841571c1..49f9e4b1f4 100644
--- a/namedev.c
+++ b/namedev.c
@@ -171,15 +171,10 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
{
char temp[NAME_SIZE];
char temp2[NAME_SIZE];
- char *tail;
- char *pos;
- char *attr;
+ char *tail, *pos, *cpos, *attr, *rest;
int len;
int i;
char c;
- char *spos;
- char *rest;
- int slen;
struct sysfs_attribute *tmpattr;
unsigned int next_free_number;
struct sysfs_class_device *class_dev_parent;
@@ -217,12 +212,14 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
dbg("substitute kernel number '%s'", udev->kernel_number);
break;
case 'm':
- strintcatmax(string, minor(udev->devt), maxsize);
- dbg("substitute minor number '%u'", minor(udev->devt));
+ sprintf(temp2, "%d", minor(udev->devt));
+ strfieldcatmax(string, temp2, maxsize);
+ dbg("substitute minor number '%s'", temp2);
break;
case 'M':
- strintcatmax(string, major(udev->devt), maxsize);
- dbg("substitute major number '%u'", major(udev->devt));
+ sprintf(temp2, "%d", major(udev->devt));
+ strfieldcatmax(string, temp2, maxsize);
+ dbg("substitute major number '%s'", temp2);
break;
case 'c':
if (udev->program_result[0] == '\0')
@@ -232,19 +229,25 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
if (attr != NULL)
i = strtoul(attr, &rest, 10);
if (i > 0) {
- foreach_strpart(udev->program_result, " \n\r", spos, slen) {
- i--;
- if (i == 0)
- break;
+ dbg("request part #%d of result string", i);
+ cpos = udev->program_result;
+ while (--i) {
+ while (cpos[0] != '\0' && !isspace(cpos[0]))
+ cpos++;
+ while (isspace(cpos[0]))
+ cpos++;
}
if (i > 0) {
dbg("requested part of result string not found");
break;
}
- if (rest[0] == '+')
- strfieldcpy(temp2, spos);
- else
- strfieldcpymax(temp2, spos, slen+1);
+ strfieldcpy(temp2, cpos);
+ /* %{2+}c copies the whole string from the second part on */
+ if (rest[0] != '+') {
+ cpos = strchr(temp2, ' ');
+ if (cpos)
+ cpos[0] = '\0';
+ }
strfieldcatmax(string, temp2, maxsize);
dbg("substitute part of result string '%s'", temp2);
} else {
diff --git a/udev_add.c b/udev_add.c
index 7e0c57fc63..aa19d874c3 100644
--- a/udev_add.c
+++ b/udev_add.c
@@ -185,8 +185,8 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de
for (i = 1; i <= udev->partitions; i++) {
dev_t part_devt;
- strfieldcpy(partitionname, filename);
- strintcat(partitionname, i);
+ snprintf(partitionname, NAME_SIZE, "%s%d", filename, i);
+ partitionname[NAME_SIZE-1] = '\0';
part_devt = makedev(major(udev->devt), minor(udev->devt)+1);
udev_make_node(udev, partitionname, part_devt, udev->mode, uid, gid);
}
diff --git a/udev_remove.c b/udev_remove.c
index 756eef0476..7a6c032d01 100644
--- a/udev_remove.c
+++ b/udev_remove.c
@@ -103,8 +103,8 @@ static int delete_node(struct udevice *udev)
return -1;
}
for (i = 1; i <= num; i++) {
- strfieldcpy(partitionname, filename);
- strintcat(partitionname, i);
+ snprintf(partitionname, NAME_SIZE, "%s%d", filename, i);
+ partitionname[NAME_SIZE-1] = '\0';
unlink_secure(partitionname);
}
}
diff --git a/udev_utils.h b/udev_utils.h
index 2f2c2497cb..3bb1b25362 100644
--- a/udev_utils.h
+++ b/udev_utils.h
@@ -48,24 +48,6 @@ do { \
strncat(to, from, maxsize - strlen(to)-1); \
} while (0)
-#define strintcat(to, i) \
-do { \
- to[sizeof(to)-1] = '\0'; \
- snprintf((to) + strlen(to), sizeof(to) - strlen(to)-1, "%u", i); \
-} while (0)
-
-#define strintcatmax(to, i, maxsize) \
-do { \
- to[maxsize-1] = '\0'; \
- snprintf((to) + strlen(to), maxsize - strlen(to)-1, "%u", i); \
-} while (0)
-
-#define foreach_strpart(str, separator, pos, len) \
- for(pos = str, len = 0; \
- (pos) < ((str) + strlen(str)); \
- pos = pos + len + strspn(pos, separator), len = strcspn(pos, separator)) \
- if (len > 0)
-
#ifdef asmlinkage
# undef asmlinkage
#endif
@@ -73,7 +55,7 @@ do { \
# define asmlinkage __attribute__((regparm(0)))
#endif
#ifndef asmlinkage
-# define asmlinkage /* nothing */
+# define asmlinkage
#endif
struct name_entry {