diff options
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/chroot.c | 10 | ||||
-rw-r--r-- | coreutils/df.c | 4 | ||||
-rw-r--r-- | coreutils/dirname.c | 9 | ||||
-rw-r--r-- | coreutils/dos2unix.c | 8 | ||||
-rw-r--r-- | coreutils/ln.c | 19 | ||||
-rw-r--r-- | coreutils/mkdir.c | 8 | ||||
-rw-r--r-- | coreutils/nohup.c | 4 | ||||
-rw-r--r-- | coreutils/stat.c | 22 | ||||
-rw-r--r-- | coreutils/stty.c | 8 | ||||
-rw-r--r-- | coreutils/yes.c | 5 |
10 files changed, 43 insertions, 54 deletions
diff --git a/coreutils/chroot.c b/coreutils/chroot.c index 9b3d70044..f7228a61a 100644 --- a/coreutils/chroot.c +++ b/coreutils/chroot.c | |||
@@ -12,18 +12,16 @@ | |||
12 | #include "libbb.h" | 12 | #include "libbb.h" |
13 | 13 | ||
14 | int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 14 | int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
15 | int chroot_main(int argc, char **argv) | 15 | int chroot_main(int argc UNUSED_PARAM, char **argv) |
16 | { | 16 | { |
17 | if (argc < 2) { | ||
18 | bb_show_usage(); | ||
19 | } | ||
20 | |||
21 | ++argv; | 17 | ++argv; |
18 | if (!*argv) | ||
19 | bb_show_usage(); | ||
22 | xchroot(*argv); | 20 | xchroot(*argv); |
23 | xchdir("/"); | 21 | xchdir("/"); |
24 | 22 | ||
25 | ++argv; | 23 | ++argv; |
26 | if (argc == 2) { | 24 | if (!*argv) { /* no 2nd param (PROG), use shell */ |
27 | argv -= 2; | 25 | argv -= 2; |
28 | argv[0] = getenv("SHELL"); | 26 | argv[0] = getenv("SHELL"); |
29 | if (!argv[0]) { | 27 | if (!argv[0]) { |
diff --git a/coreutils/df.c b/coreutils/df.c index a0e6fe070..11a739816 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -35,7 +35,7 @@ static unsigned long kscale(unsigned long b, unsigned long bs) | |||
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 37 | int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
38 | int df_main(int argc, char **argv) | 38 | int df_main(int argc UNUSED_PARAM, char **argv) |
39 | { | 39 | { |
40 | unsigned long blocks_used; | 40 | unsigned long blocks_used; |
41 | unsigned blocks_percent_used; | 41 | unsigned blocks_percent_used; |
@@ -105,7 +105,7 @@ int df_main(int argc, char **argv) | |||
105 | 105 | ||
106 | mount_table = NULL; | 106 | mount_table = NULL; |
107 | argv += optind; | 107 | argv += optind; |
108 | if (optind >= argc) { | 108 | if (!argv[0]) { |
109 | mount_table = setmntent(bb_path_mtab_file, "r"); | 109 | mount_table = setmntent(bb_path_mtab_file, "r"); |
110 | if (!mount_table) | 110 | if (!mount_table) |
111 | bb_perror_msg_and_die(bb_path_mtab_file); | 111 | bb_perror_msg_and_die(bb_path_mtab_file); |
diff --git a/coreutils/dirname.c b/coreutils/dirname.c index 1f5f70dfd..94c22a7ee 100644 --- a/coreutils/dirname.c +++ b/coreutils/dirname.c | |||
@@ -15,13 +15,8 @@ | |||
15 | /* This is a NOFORK applet. Be very careful! */ | 15 | /* This is a NOFORK applet. Be very careful! */ |
16 | 16 | ||
17 | int dirname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 17 | int dirname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
18 | int dirname_main(int argc, char **argv) | 18 | int dirname_main(int argc UNUSED_PARAM, char **argv) |
19 | { | 19 | { |
20 | if (argc != 2) { | 20 | puts(dirname(single_argv(argv))); |
21 | bb_show_usage(); | ||
22 | } | ||
23 | |||
24 | puts(dirname(argv[1])); | ||
25 | |||
26 | return fflush_all(); | 21 | return fflush_all(); |
27 | } | 22 | } |
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c index baf879e54..1911f5319 100644 --- a/coreutils/dos2unix.c +++ b/coreutils/dos2unix.c | |||
@@ -69,7 +69,7 @@ static void convert(char *fn, int conv_type) | |||
69 | } | 69 | } |
70 | 70 | ||
71 | int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 71 | int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
72 | int dos2unix_main(int argc, char **argv) | 72 | int dos2unix_main(int argc UNUSED_PARAM, char **argv) |
73 | { | 73 | { |
74 | int o, conv_type; | 74 | int o, conv_type; |
75 | 75 | ||
@@ -88,11 +88,11 @@ int dos2unix_main(int argc, char **argv) | |||
88 | if (o) | 88 | if (o) |
89 | conv_type = o; | 89 | conv_type = o; |
90 | 90 | ||
91 | argv += optind; | ||
91 | do { | 92 | do { |
92 | /* might be convert(NULL) if there is no filename given */ | 93 | /* might be convert(NULL) if there is no filename given */ |
93 | convert(argv[optind], conv_type); | 94 | convert(*argv, conv_type); |
94 | optind++; | 95 | } while (*++argv); |
95 | } while (optind < argc); | ||
96 | 96 | ||
97 | return 0; | 97 | return 0; |
98 | } | 98 | } |
diff --git a/coreutils/ln.c b/coreutils/ln.c index eb7171959..f977aa177 100644 --- a/coreutils/ln.c +++ b/coreutils/ln.c | |||
@@ -26,7 +26,7 @@ int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
26 | int ln_main(int argc, char **argv) | 26 | int ln_main(int argc, char **argv) |
27 | { | 27 | { |
28 | int status = EXIT_SUCCESS; | 28 | int status = EXIT_SUCCESS; |
29 | int flag; | 29 | int opts; |
30 | char *last; | 30 | char *last; |
31 | char *src_name; | 31 | char *src_name; |
32 | char *src; | 32 | char *src; |
@@ -34,11 +34,8 @@ int ln_main(int argc, char **argv) | |||
34 | struct stat statbuf; | 34 | struct stat statbuf; |
35 | int (*link_func)(const char *, const char *); | 35 | int (*link_func)(const char *, const char *); |
36 | 36 | ||
37 | flag = getopt32(argv, "sfnbS:", &suffix); | 37 | opt_complementary = "-1"; /* min one arg */ |
38 | 38 | opts = getopt32(argv, "sfnbS:", &suffix); | |
39 | if (argc == optind) { | ||
40 | bb_show_usage(); | ||
41 | } | ||
42 | 39 | ||
43 | last = argv[argc - 1]; | 40 | last = argv[argc - 1]; |
44 | argv += optind; | 41 | argv += optind; |
@@ -53,7 +50,7 @@ int ln_main(int argc, char **argv) | |||
53 | src = last; | 50 | src = last; |
54 | 51 | ||
55 | if (is_directory(src, | 52 | if (is_directory(src, |
56 | (flag & LN_NODEREFERENCE) ^ LN_NODEREFERENCE, | 53 | (opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE, |
57 | NULL) | 54 | NULL) |
58 | ) { | 55 | ) { |
59 | src_name = xstrdup(*argv); | 56 | src_name = xstrdup(*argv); |
@@ -61,7 +58,7 @@ int ln_main(int argc, char **argv) | |||
61 | free(src_name); | 58 | free(src_name); |
62 | src_name = src; | 59 | src_name = src; |
63 | } | 60 | } |
64 | if (!(flag & LN_SYMLINK) && stat(*argv, &statbuf)) { | 61 | if (!(opts & LN_SYMLINK) && stat(*argv, &statbuf)) { |
65 | // coreutils: "ln dangling_symlink new_hardlink" works | 62 | // coreutils: "ln dangling_symlink new_hardlink" works |
66 | if (lstat(*argv, &statbuf) || !S_ISLNK(statbuf.st_mode)) { | 63 | if (lstat(*argv, &statbuf) || !S_ISLNK(statbuf.st_mode)) { |
67 | bb_simple_perror_msg(*argv); | 64 | bb_simple_perror_msg(*argv); |
@@ -71,7 +68,7 @@ int ln_main(int argc, char **argv) | |||
71 | } | 68 | } |
72 | } | 69 | } |
73 | 70 | ||
74 | if (flag & LN_BACKUP) { | 71 | if (opts & LN_BACKUP) { |
75 | char *backup; | 72 | char *backup; |
76 | backup = xasprintf("%s%s", src, suffix); | 73 | backup = xasprintf("%s%s", src, suffix); |
77 | if (rename(src, backup) < 0 && errno != ENOENT) { | 74 | if (rename(src, backup) < 0 && errno != ENOENT) { |
@@ -87,12 +84,12 @@ int ln_main(int argc, char **argv) | |||
87 | * Therefore, always unlink(). | 84 | * Therefore, always unlink(). |
88 | */ | 85 | */ |
89 | unlink(src); | 86 | unlink(src); |
90 | } else if (flag & LN_FORCE) { | 87 | } else if (opts & LN_FORCE) { |
91 | unlink(src); | 88 | unlink(src); |
92 | } | 89 | } |
93 | 90 | ||
94 | link_func = link; | 91 | link_func = link; |
95 | if (flag & LN_SYMLINK) { | 92 | if (opts & LN_SYMLINK) { |
96 | link_func = symlink; | 93 | link_func = symlink; |
97 | } | 94 | } |
98 | 95 | ||
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c index a110165db..c837e9726 100644 --- a/coreutils/mkdir.c +++ b/coreutils/mkdir.c | |||
@@ -34,7 +34,7 @@ static const char mkdir_longopts[] ALIGN1 = | |||
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 36 | int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
37 | int mkdir_main(int argc, char **argv) | 37 | int mkdir_main(int argc UNUSED_PARAM, char **argv) |
38 | { | 38 | { |
39 | mode_t mode = (mode_t)(-1); | 39 | mode_t mode = (mode_t)(-1); |
40 | int status = EXIT_SUCCESS; | 40 | int status = EXIT_SUCCESS; |
@@ -64,11 +64,9 @@ int mkdir_main(int argc, char **argv) | |||
64 | } | 64 | } |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | if (optind == argc) { | ||
68 | bb_show_usage(); | ||
69 | } | ||
70 | |||
71 | argv += optind; | 67 | argv += optind; |
68 | if (!argv[0]) | ||
69 | bb_show_usage(); | ||
72 | 70 | ||
73 | do { | 71 | do { |
74 | if (bb_make_directory(*argv, mode, flags)) { | 72 | if (bb_make_directory(*argv, mode, flags)) { |
diff --git a/coreutils/nohup.c b/coreutils/nohup.c index f44e2af61..c9e65d2ba 100644 --- a/coreutils/nohup.c +++ b/coreutils/nohup.c | |||
@@ -32,14 +32,14 @@ nohup: redirecting stderr to stdout | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | int nohup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 34 | int nohup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
35 | int nohup_main(int argc, char **argv) | 35 | int nohup_main(int argc UNUSED_PARAM, char **argv) |
36 | { | 36 | { |
37 | const char *nohupout; | 37 | const char *nohupout; |
38 | char *home; | 38 | char *home; |
39 | 39 | ||
40 | xfunc_error_retval = 127; | 40 | xfunc_error_retval = 127; |
41 | 41 | ||
42 | if (argc < 2) bb_show_usage(); | 42 | if (!argv[1]) bb_show_usage(); |
43 | 43 | ||
44 | /* If stdin is a tty, detach from it. */ | 44 | /* If stdin is a tty, detach from it. */ |
45 | if (isatty(STDIN_FILENO)) { | 45 | if (isatty(STDIN_FILENO)) { |
diff --git a/coreutils/stat.c b/coreutils/stat.c index 2bc9a086c..bbd2e6a7c 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c | |||
@@ -640,29 +640,29 @@ static bool do_stat(const char *filename, const char *format) | |||
640 | } | 640 | } |
641 | 641 | ||
642 | int stat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 642 | int stat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
643 | int stat_main(int argc, char **argv) | 643 | int stat_main(int argc UNUSED_PARAM, char **argv) |
644 | { | 644 | { |
645 | IF_FEATURE_STAT_FORMAT(char *format = NULL;) | 645 | IF_FEATURE_STAT_FORMAT(char *format = NULL;) |
646 | int i; | 646 | int i; |
647 | int ok = 1; | 647 | int ok; |
648 | unsigned opts; | ||
648 | statfunc_ptr statfunc = do_stat; | 649 | statfunc_ptr statfunc = do_stat; |
649 | 650 | ||
650 | getopt32(argv, "ftL" | 651 | opt_complementary = "-1"; /* min one arg */ |
652 | opts = getopt32(argv, "ftL" | ||
651 | IF_SELINUX("Z") | 653 | IF_SELINUX("Z") |
652 | IF_FEATURE_STAT_FORMAT("c:", &format) | 654 | IF_FEATURE_STAT_FORMAT("c:", &format) |
653 | ); | 655 | ); |
654 | 656 | if (opts & OPT_FILESYS) /* -f */ | |
655 | if (option_mask32 & OPT_FILESYS) /* -f */ | ||
656 | statfunc = do_statfs; | 657 | statfunc = do_statfs; |
657 | if (argc == optind) /* files */ | ||
658 | bb_show_usage(); | ||
659 | |||
660 | #if ENABLE_SELINUX | 658 | #if ENABLE_SELINUX |
661 | if (option_mask32 & OPT_SELINUX) { | 659 | if (opts & OPT_SELINUX) { |
662 | selinux_or_die(); | 660 | selinux_or_die(); |
663 | } | 661 | } |
664 | #endif /* ENABLE_SELINUX */ | 662 | #endif |
665 | for (i = optind; i < argc; ++i) | 663 | ok = 1; |
664 | argv += optind; | ||
665 | for (i = 0; argv[i]; ++i) | ||
666 | ok &= statfunc(argv[i] IF_FEATURE_STAT_FORMAT(, format)); | 666 | ok &= statfunc(argv[i] IF_FEATURE_STAT_FORMAT(, format)); |
667 | 667 | ||
668 | return (ok ? EXIT_SUCCESS : EXIT_FAILURE); | 668 | return (ok ? EXIT_SUCCESS : EXIT_FAILURE); |
diff --git a/coreutils/stty.c b/coreutils/stty.c index f29fa64f7..0485b8011 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -1156,7 +1156,7 @@ static void set_control_char_or_die(const struct control_info *info, | |||
1156 | #define STTY_noargs (1 << 4) | 1156 | #define STTY_noargs (1 << 4) |
1157 | 1157 | ||
1158 | int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1158 | int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1159 | int stty_main(int argc, char **argv) | 1159 | int stty_main(int argc UNUSED_PARAM, char **argv) |
1160 | { | 1160 | { |
1161 | struct termios mode; | 1161 | struct termios mode; |
1162 | void (*output_func)(const struct termios *, const int); | 1162 | void (*output_func)(const struct termios *, const int); |
@@ -1211,8 +1211,10 @@ int stty_main(int argc, char **argv) | |||
1211 | if (!file_name) | 1211 | if (!file_name) |
1212 | bb_error_msg_and_die(bb_msg_requires_arg, "-F"); | 1212 | bb_error_msg_and_die(bb_msg_requires_arg, "-F"); |
1213 | /* remove -F param from arg[vc] */ | 1213 | /* remove -F param from arg[vc] */ |
1214 | --argc; | 1214 | while (argv[p]) { |
1215 | while (argv[p]) { argv[p] = argv[p+1]; ++p; } | 1215 | argv[p] = argv[p+1]; |
1216 | ++p; | ||
1217 | } | ||
1216 | } | 1218 | } |
1217 | goto end_option; | 1219 | goto end_option; |
1218 | default: | 1220 | default: |
diff --git a/coreutils/yes.c b/coreutils/yes.c index 9d3f67550..d757a4504 100644 --- a/coreutils/yes.c +++ b/coreutils/yes.c | |||
@@ -19,14 +19,13 @@ | |||
19 | /* This is a NOFORK applet. Be very careful! */ | 19 | /* This is a NOFORK applet. Be very careful! */ |
20 | 20 | ||
21 | int yes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 21 | int yes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
22 | int yes_main(int argc, char **argv) | 22 | int yes_main(int argc UNUSED_PARAM, char **argv) |
23 | { | 23 | { |
24 | char **pp; | 24 | char **pp; |
25 | 25 | ||
26 | argv[0] = (char*)"y"; | 26 | argv[0] = (char*)"y"; |
27 | if (argc != 1) { | 27 | if (argv[1]) |
28 | ++argv; | 28 | ++argv; |
29 | } | ||
30 | 29 | ||
31 | do { | 30 | do { |
32 | pp = argv; | 31 | pp = argv; |