makedevs: code shrink
function old new delta makedevs_main 1071 1052 -19 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
3532e60ca8
commit
3c9688e587
@ -262,9 +262,7 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (chmod(full_name, mode) < 0)
|
if (chmod(full_name, mode) < 0)
|
||||||
goto chmod_fail;
|
goto chmod_fail;
|
||||||
} else {
|
} else {
|
||||||
dev_t rdev;
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
char *full_name_inc;
|
|
||||||
|
|
||||||
if (type == 'p') {
|
if (type == 'p') {
|
||||||
mode |= S_IFIFO;
|
mode |= S_IFIFO;
|
||||||
@ -278,26 +276,29 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
full_name_inc = xmalloc(strlen(full_name) + sizeof(int)*3 + 2);
|
if (count != 0)
|
||||||
if (count)
|
|
||||||
count--;
|
count--;
|
||||||
for (i = start; i <= start + count; i++) {
|
for (i = 0; i <= count; i++) {
|
||||||
sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i);
|
dev_t rdev;
|
||||||
rdev = makedev(major, minor + (i - start) * increment);
|
char *nameN = full_name;
|
||||||
if (mknod(full_name_inc, mode, rdev) != 0
|
if (count != 0)
|
||||||
|
nameN = xasprintf("%s%u", full_name, start + i);
|
||||||
|
rdev = makedev(major, minor + i * increment);
|
||||||
|
if (mknod(nameN, mode, rdev) != 0
|
||||||
&& errno != EEXIST
|
&& errno != EEXIST
|
||||||
) {
|
) {
|
||||||
bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc);
|
bb_perror_msg("line %d: can't create node %s", linenum, nameN);
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
} else if (chown(full_name_inc, uid, gid) < 0) {
|
} else if (chown(nameN, uid, gid) < 0) {
|
||||||
bb_perror_msg("line %d: can't chown %s", linenum, full_name_inc);
|
bb_perror_msg("line %d: can't chown %s", linenum, nameN);
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
} else if (chmod(full_name_inc, mode) < 0) {
|
} else if (chmod(nameN, mode) < 0) {
|
||||||
bb_perror_msg("line %d: can't chmod %s", linenum, full_name_inc);
|
bb_perror_msg("line %d: can't chmod %s", linenum, nameN);
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
if (count != 0)
|
||||||
|
free(nameN);
|
||||||
}
|
}
|
||||||
free(full_name_inc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ENABLE_FEATURE_CLEAN_UP)
|
if (ENABLE_FEATURE_CLEAN_UP)
|
||||||
|
Loading…
Reference in New Issue
Block a user