summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko2009-11-28 15:18:53 +0100
committerDenys Vlasenko2009-11-28 15:18:53 +0100
commite992bae6f9adf3718c6263a36c004ead1c7272a8 (patch)
treef0bc9e4fa145f58ab3f9838902e09f9cfba29648 /coreutils
parent86cfb70ca5f2bde11f2d071bc59db75291d8552f (diff)
downloadbusybox-e992bae6f9adf3718c6263a36c004ead1c7272a8.zip
busybox-e992bae6f9adf3718c6263a36c004ead1c7272a8.tar.gz
*: remove a few more cases of argc usage. -89 bytes.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/chroot.c10
-rw-r--r--coreutils/df.c4
-rw-r--r--coreutils/dirname.c9
-rw-r--r--coreutils/dos2unix.c8
-rw-r--r--coreutils/ln.c19
-rw-r--r--coreutils/mkdir.c8
-rw-r--r--coreutils/nohup.c4
-rw-r--r--coreutils/stat.c22
-rw-r--r--coreutils/stty.c8
-rw-r--r--coreutils/yes.c5
10 files changed, 43 insertions, 54 deletions
diff --git a/coreutils/chroot.c b/coreutils/chroot.c
index 9b3d700..f7228a6 100644
--- a/coreutils/chroot.c
+++ b/coreutils/chroot.c
@@ -12,18 +12,16 @@
#include "libbb.h"
int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int chroot_main(int argc, char **argv)
+int chroot_main(int argc UNUSED_PARAM, char **argv)
{
- if (argc < 2) {
- bb_show_usage();
- }
-
++argv;
+ if (!*argv)
+ bb_show_usage();
xchroot(*argv);
xchdir("/");
++argv;
- if (argc == 2) {
+ if (!*argv) { /* no 2nd param (PROG), use shell */
argv -= 2;
argv[0] = getenv("SHELL");
if (!argv[0]) {
diff --git a/coreutils/df.c b/coreutils/df.c
index a0e6fe0..11a7398 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -35,7 +35,7 @@ static unsigned long kscale(unsigned long b, unsigned long bs)
#endif
int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int df_main(int argc, char **argv)
+int df_main(int argc UNUSED_PARAM, char **argv)
{
unsigned long blocks_used;
unsigned blocks_percent_used;
@@ -105,7 +105,7 @@ int df_main(int argc, char **argv)
mount_table = NULL;
argv += optind;
- if (optind >= argc) {
+ if (!argv[0]) {
mount_table = setmntent(bb_path_mtab_file, "r");
if (!mount_table)
bb_perror_msg_and_die(bb_path_mtab_file);
diff --git a/coreutils/dirname.c b/coreutils/dirname.c
index 1f5f70d..94c22a7 100644
--- a/coreutils/dirname.c
+++ b/coreutils/dirname.c
@@ -15,13 +15,8 @@
/* This is a NOFORK applet. Be very careful! */
int dirname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int dirname_main(int argc, char **argv)
+int dirname_main(int argc UNUSED_PARAM, char **argv)
{
- if (argc != 2) {
- bb_show_usage();
- }
-
- puts(dirname(argv[1]));
-
+ puts(dirname(single_argv(argv)));
return fflush_all();
}
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c
index baf879e..1911f53 100644
--- a/coreutils/dos2unix.c
+++ b/coreutils/dos2unix.c
@@ -69,7 +69,7 @@ static void convert(char *fn, int conv_type)
}
int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int dos2unix_main(int argc, char **argv)
+int dos2unix_main(int argc UNUSED_PARAM, char **argv)
{
int o, conv_type;
@@ -88,11 +88,11 @@ int dos2unix_main(int argc, char **argv)
if (o)
conv_type = o;
+ argv += optind;
do {
/* might be convert(NULL) if there is no filename given */
- convert(argv[optind], conv_type);
- optind++;
- } while (optind < argc);
+ convert(*argv, conv_type);
+ } while (*++argv);
return 0;
}
diff --git a/coreutils/ln.c b/coreutils/ln.c
index eb71719..f977aa1 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -26,7 +26,7 @@ int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ln_main(int argc, char **argv)
{
int status = EXIT_SUCCESS;
- int flag;
+ int opts;
char *last;
char *src_name;
char *src;
@@ -34,11 +34,8 @@ int ln_main(int argc, char **argv)
struct stat statbuf;
int (*link_func)(const char *, const char *);
- flag = getopt32(argv, "sfnbS:", &suffix);
-
- if (argc == optind) {
- bb_show_usage();
- }
+ opt_complementary = "-1"; /* min one arg */
+ opts = getopt32(argv, "sfnbS:", &suffix);
last = argv[argc - 1];
argv += optind;
@@ -53,7 +50,7 @@ int ln_main(int argc, char **argv)
src = last;
if (is_directory(src,
- (flag & LN_NODEREFERENCE) ^ LN_NODEREFERENCE,
+ (opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE,
NULL)
) {
src_name = xstrdup(*argv);
@@ -61,7 +58,7 @@ int ln_main(int argc, char **argv)
free(src_name);
src_name = src;
}
- if (!(flag & LN_SYMLINK) && stat(*argv, &statbuf)) {
+ if (!(opts & LN_SYMLINK) && stat(*argv, &statbuf)) {
// coreutils: "ln dangling_symlink new_hardlink" works
if (lstat(*argv, &statbuf) || !S_ISLNK(statbuf.st_mode)) {
bb_simple_perror_msg(*argv);
@@ -71,7 +68,7 @@ int ln_main(int argc, char **argv)
}
}
- if (flag & LN_BACKUP) {
+ if (opts & LN_BACKUP) {
char *backup;
backup = xasprintf("%s%s", src, suffix);
if (rename(src, backup) < 0 && errno != ENOENT) {
@@ -87,12 +84,12 @@ int ln_main(int argc, char **argv)
* Therefore, always unlink().
*/
unlink(src);
- } else if (flag & LN_FORCE) {
+ } else if (opts & LN_FORCE) {
unlink(src);
}
link_func = link;
- if (flag & LN_SYMLINK) {
+ if (opts & LN_SYMLINK) {
link_func = symlink;
}
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index a110165..c837e97 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -34,7 +34,7 @@ static const char mkdir_longopts[] ALIGN1 =
#endif
int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int mkdir_main(int argc, char **argv)
+int mkdir_main(int argc UNUSED_PARAM, char **argv)
{
mode_t mode = (mode_t)(-1);
int status = EXIT_SUCCESS;
@@ -64,11 +64,9 @@ int mkdir_main(int argc, char **argv)
}
#endif
- if (optind == argc) {
- bb_show_usage();
- }
-
argv += optind;
+ if (!argv[0])
+ bb_show_usage();
do {
if (bb_make_directory(*argv, mode, flags)) {
diff --git a/coreutils/nohup.c b/coreutils/nohup.c
index f44e2af..c9e65d2 100644
--- a/coreutils/nohup.c
+++ b/coreutils/nohup.c
@@ -32,14 +32,14 @@ nohup: redirecting stderr to stdout
*/
int nohup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int nohup_main(int argc, char **argv)
+int nohup_main(int argc UNUSED_PARAM, char **argv)
{
const char *nohupout;
char *home;
xfunc_error_retval = 127;
- if (argc < 2) bb_show_usage();
+ if (!argv[1]) bb_show_usage();
/* If stdin is a tty, detach from it. */
if (isatty(STDIN_FILENO)) {
diff --git a/coreutils/stat.c b/coreutils/stat.c
index 2bc9a08..bbd2e6a 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -640,29 +640,29 @@ static bool do_stat(const char *filename, const char *format)
}
int stat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int stat_main(int argc, char **argv)
+int stat_main(int argc UNUSED_PARAM, char **argv)
{
IF_FEATURE_STAT_FORMAT(char *format = NULL;)
int i;
- int ok = 1;
+ int ok;
+ unsigned opts;
statfunc_ptr statfunc = do_stat;
- getopt32(argv, "ftL"
+ opt_complementary = "-1"; /* min one arg */
+ opts = getopt32(argv, "ftL"
IF_SELINUX("Z")
IF_FEATURE_STAT_FORMAT("c:", &format)
);
-
- if (option_mask32 & OPT_FILESYS) /* -f */
+ if (opts & OPT_FILESYS) /* -f */
statfunc = do_statfs;
- if (argc == optind) /* files */
- bb_show_usage();
-
#if ENABLE_SELINUX
- if (option_mask32 & OPT_SELINUX) {
+ if (opts & OPT_SELINUX) {
selinux_or_die();
}
-#endif /* ENABLE_SELINUX */
- for (i = optind; i < argc; ++i)
+#endif
+ ok = 1;
+ argv += optind;
+ for (i = 0; argv[i]; ++i)
ok &= statfunc(argv[i] IF_FEATURE_STAT_FORMAT(, format));
return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
diff --git a/coreutils/stty.c b/coreutils/stty.c
index f29fa64..0485b80 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,
#define STTY_noargs (1 << 4)
int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int stty_main(int argc, char **argv)
+int stty_main(int argc UNUSED_PARAM, char **argv)
{
struct termios mode;
void (*output_func)(const struct termios *, const int);
@@ -1211,8 +1211,10 @@ int stty_main(int argc, char **argv)
if (!file_name)
bb_error_msg_and_die(bb_msg_requires_arg, "-F");
/* remove -F param from arg[vc] */
- --argc;
- while (argv[p]) { argv[p] = argv[p+1]; ++p; }
+ while (argv[p]) {
+ argv[p] = argv[p+1];
+ ++p;
+ }
}
goto end_option;
default:
diff --git a/coreutils/yes.c b/coreutils/yes.c
index 9d3f675..d757a45 100644
--- a/coreutils/yes.c
+++ b/coreutils/yes.c
@@ -19,14 +19,13 @@
/* This is a NOFORK applet. Be very careful! */
int yes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int yes_main(int argc, char **argv)
+int yes_main(int argc UNUSED_PARAM, char **argv)
{
char **pp;
argv[0] = (char*)"y";
- if (argc != 1) {
+ if (argv[1])
++argv;
- }
do {
pp = argv;