1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-22 06:50:18 +03:00

[PATCH] replace weird defines by real code

This commit is contained in:
kay.sievers@vrfy.org 2005-03-05 06:50:09 +01:00 committed by Greg KH
parent 51015808da
commit 03fd7a3ad3
4 changed files with 26 additions and 41 deletions

View File

@ -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 {

View 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);
}

View 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);
}
}

View 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 {