diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-06 02:17:24 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-06 02:17:24 +0200 |
commit | 3c9688e58737665d204ab70e6b0e10c745c99c30 (patch) | |
tree | 6d1e3dcbf6c2a7af2aae50fe80918f63aaad3618 /miscutils | |
parent | 3532e60ca890979030949793933442afaec272fb (diff) | |
download | busybox-3c9688e58737665d204ab70e6b0e10c745c99c30.tar.gz |
makedevs: code shrink
function old new delta
makedevs_main 1071 1052 -19
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/makedevs.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c index fec1045e4..f436b08f8 100644 --- a/miscutils/makedevs.c +++ b/miscutils/makedevs.c @@ -262,9 +262,7 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv) if (chmod(full_name, mode) < 0) goto chmod_fail; } else { - dev_t rdev; unsigned i; - char *full_name_inc; if (type == 'p') { mode |= S_IFIFO; @@ -278,26 +276,29 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv) continue; } - full_name_inc = xmalloc(strlen(full_name) + sizeof(int)*3 + 2); - if (count) + if (count != 0) count--; - for (i = start; i <= start + count; i++) { - sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i); - rdev = makedev(major, minor + (i - start) * increment); - if (mknod(full_name_inc, mode, rdev) != 0 + for (i = 0; i <= count; i++) { + dev_t rdev; + char *nameN = full_name; + 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 ) { - 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; - } else if (chown(full_name_inc, uid, gid) < 0) { - bb_perror_msg("line %d: can't chown %s", linenum, full_name_inc); + } else if (chown(nameN, uid, gid) < 0) { + bb_perror_msg("line %d: can't chown %s", linenum, nameN); ret = EXIT_FAILURE; - } else if (chmod(full_name_inc, mode) < 0) { - bb_perror_msg("line %d: can't chmod %s", linenum, full_name_inc); + } else if (chmod(nameN, mode) < 0) { + bb_perror_msg("line %d: can't chmod %s", linenum, nameN); ret = EXIT_FAILURE; } + if (count != 0) + free(nameN); } - free(full_name_inc); } } if (ENABLE_FEATURE_CLEAN_UP) |