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 | |
| parent | 3532e60ca890979030949793933442afaec272fb (diff) | |
| download | busybox-w32-3c9688e58737665d204ab70e6b0e10c745c99c30.tar.gz busybox-w32-3c9688e58737665d204ab70e6b0e10c745c99c30.tar.bz2 busybox-w32-3c9688e58737665d204ab70e6b0e10c745c99c30.zip | |
makedevs: code shrink
function old new delta
makedevs_main 1071 1052 -19
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -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) | |||
| 262 | if (chmod(full_name, mode) < 0) | 262 | if (chmod(full_name, mode) < 0) |
| 263 | goto chmod_fail; | 263 | goto chmod_fail; |
| 264 | } else { | 264 | } else { |
| 265 | dev_t rdev; | ||
| 266 | unsigned i; | 265 | unsigned i; |
| 267 | char *full_name_inc; | ||
| 268 | 266 | ||
| 269 | if (type == 'p') { | 267 | if (type == 'p') { |
| 270 | mode |= S_IFIFO; | 268 | mode |= S_IFIFO; |
| @@ -278,26 +276,29 @@ int makedevs_main(int argc UNUSED_PARAM, char **argv) | |||
| 278 | continue; | 276 | continue; |
| 279 | } | 277 | } |
| 280 | 278 | ||
| 281 | full_name_inc = xmalloc(strlen(full_name) + sizeof(int)*3 + 2); | 279 | if (count != 0) |
| 282 | if (count) | ||
| 283 | count--; | 280 | count--; |
| 284 | for (i = start; i <= start + count; i++) { | 281 | for (i = 0; i <= count; i++) { |
| 285 | sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i); | 282 | dev_t rdev; |
| 286 | rdev = makedev(major, minor + (i - start) * increment); | 283 | char *nameN = full_name; |
| 287 | if (mknod(full_name_inc, mode, rdev) != 0 | 284 | if (count != 0) |
| 285 | nameN = xasprintf("%s%u", full_name, start + i); | ||
| 286 | rdev = makedev(major, minor + i * increment); | ||
| 287 | if (mknod(nameN, mode, rdev) != 0 | ||
| 288 | && errno != EEXIST | 288 | && errno != EEXIST |
| 289 | ) { | 289 | ) { |
| 290 | bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc); | 290 | bb_perror_msg("line %d: can't create node %s", linenum, nameN); |
| 291 | ret = EXIT_FAILURE; | 291 | ret = EXIT_FAILURE; |
| 292 | } else if (chown(full_name_inc, uid, gid) < 0) { | 292 | } else if (chown(nameN, uid, gid) < 0) { |
| 293 | bb_perror_msg("line %d: can't chown %s", linenum, full_name_inc); | 293 | bb_perror_msg("line %d: can't chown %s", linenum, nameN); |
| 294 | ret = EXIT_FAILURE; | 294 | ret = EXIT_FAILURE; |
| 295 | } else if (chmod(full_name_inc, mode) < 0) { | 295 | } else if (chmod(nameN, mode) < 0) { |
| 296 | bb_perror_msg("line %d: can't chmod %s", linenum, full_name_inc); | 296 | bb_perror_msg("line %d: can't chmod %s", linenum, nameN); |
| 297 | ret = EXIT_FAILURE; | 297 | ret = EXIT_FAILURE; |
| 298 | } | 298 | } |
| 299 | if (count != 0) | ||
| 300 | free(nameN); | ||
| 299 | } | 301 | } |
| 300 | free(full_name_inc); | ||
| 301 | } | 302 | } |
| 302 | } | 303 | } |
| 303 | if (ENABLE_FEATURE_CLEAN_UP) | 304 | if (ENABLE_FEATURE_CLEAN_UP) |
