]> err.no Git - systemd/commitdiff
[PATCH] replace weird defines by real code
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Sat, 5 Mar 2005 05:50:09 +0000 (06:50 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 06:48:48 +0000 (23:48 -0700)
namedev.c
udev_add.c
udev_remove.c
udev_utils.h

index 91841571c170130d5303bb88f1c92c5ed41e3a09..49f9e4b1f48e30f21068179162d7b1015944eaed 100644 (file)
--- 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 {
index 7e0c57fc632041ba8a3627d57adb7e23a43aa019..aa19d874c3b31fd85760f42761287e7879ae6f58 100644 (file)
@@ -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);
                        }
index 756eef047682b5f9079c86c8ac36a5b1bd7a64e3..7a6c032d01cbbf39c638c3489dce0e6932a64af8 100644 (file)
@@ -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);
                }
        }
index 2f2c2497cbad6afd70559f5165cc688f9fdf5bba..3bb1b25362a2dfcb6aa351446da17eea09ea7591 100644 (file)
@@ -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 {