Permalink
Browse files

*: remove some uses of argc

function                                             old     new   delta
whoami_main                                           34      37      +3
logname_main                                          60      63      +3
hostid_main                                           35      38      +3
ttysize_main                                         136     135      -1
nmeter_main                                          673     672      -1
logger_main                                          387     386      -1
uuencode_main                                        330     328      -2
ifupdown_main                                       2125    2123      -2
mesg_main                                            158     155      -3
free_main                                            333     330      -3
cal_main                                             902     899      -3
acpid_main                                           443     440      -3
ar_main                                              196     189      -7
find_main                                            476     467      -9
ifconfig_main                                       1235    1221     -14
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/12 up/down: 9/-49)            Total: -40 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
  • Loading branch information...
Denys Vlasenko
Denys Vlasenko committed Jan 4, 2010
1 parent a355da0 commit 2ec91aead52d6ea6a42420005119ebb281a76cdc
View
@@ -38,7 +38,7 @@ static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
#define AR_OPT_INSERT 0x40
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int ar_main(int argc, char **argv)
+int ar_main(int argc UNUSED_PARAM, char **argv)
{
static const char msg_unsupported_err[] ALIGN1 =
"archive %s is not supported";
@@ -51,6 +51,7 @@ int ar_main(int argc, char **argv)
/* Prepend '-' to the first argument if required */
opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt";
opt = getopt32(argv, "ptxovcr");
+ argv += optind;
if (opt & AR_CTX_PRINT) {
archive_handle->action_data = data_extract_to_stdout;
@@ -76,9 +77,9 @@ int ar_main(int argc, char **argv)
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
- while (optind < argc) {
+ while (*argv) {
archive_handle->filter = filter_accept_list;
- llist_add_to(&(archive_handle->accept), argv[optind++]);
+ llist_add_to(&archive_handle->accept, *argv++);
}
unpack_ar_archive(archive_handle);
View
@@ -116,7 +116,9 @@ int rpm_main(int argc, char **argv)
}
argv += optind;
//argc -= optind;
- if (!argv[0]) bb_show_usage();
+ if (!argv[0]) {
+ bb_show_usage();
+ }
while (*argv) {
rpm_fd = xopen(*argv++, O_RDONLY);
View
@@ -77,7 +77,7 @@ static char *build_row(char *p, unsigned *dp);
#define HEAD_SEP 2 /* spaces between day headings */
int cal_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int cal_main(int argc, char **argv)
+int cal_main(int argc UNUSED_PARAM, char **argv)
{
struct tm *local_time;
struct tm zero_tm;
@@ -92,21 +92,19 @@ int cal_main(int argc, char **argv)
option_mask32 &= 1;
month = 0;
argv += optind;
- argc -= optind;
- if (argc > 2) {
- bb_show_usage();
- }
-
- if (!argc) {
+ if (!argv[0]) {
time(&now);
local_time = localtime(&now);
year = local_time->tm_year + 1900;
if (!(flags & 2)) { /* no -y */
month = local_time->tm_mon + 1;
}
} else {
- if (argc == 2) {
+ if (argv[1]) {
+ if (argv[2]) {
+ bb_show_usage();
+ }
month = xatou_range(*argv++, 1, 12);
}
year = xatou_range(*argv, 1, 9999);
View
@@ -14,9 +14,9 @@
/* This is a NOFORK applet. Be very careful! */
int hostid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int hostid_main(int argc, char **argv UNUSED_PARAM)
+int hostid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
- if (argc > 1) {
+ if (argv[1]) {
bb_show_usage();
}
View
@@ -25,11 +25,11 @@
/* This is a NOFORK applet. Be very careful! */
int logname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int logname_main(int argc, char **argv UNUSED_PARAM)
+int logname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
char buf[64];
- if (argc > 1) {
+ if (argv[1]) {
bb_show_usage();
}
View
@@ -39,7 +39,9 @@ int nohup_main(int argc UNUSED_PARAM, char **argv)
xfunc_error_retval = 127;
- if (!argv[1]) bb_show_usage();
+ if (!argv[1]) {
+ bb_show_usage();
+ }
/* If stdin is a tty, detach from it. */
if (isatty(STDIN_FILENO)) {
View
@@ -16,7 +16,7 @@ enum {
};
int uuencode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int uuencode_main(int argc, char **argv)
+int uuencode_main(int argc UNUSED_PARAM, char **argv)
{
struct stat stat_buf;
int src_fd = STDIN_FILENO;
@@ -32,7 +32,7 @@ int uuencode_main(int argc, char **argv)
tbl = bb_uuenc_tbl_base64;
}
argv += optind;
- if (argc == optind + 2) {
+ if (argv[1]) {
src_fd = xopen(*argv, O_RDONLY);
fstat(src_fd, &stat_buf);
mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
View
@@ -14,9 +14,9 @@
/* This is a NOFORK applet. Be very careful! */
int whoami_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int whoami_main(int argc, char **argv UNUSED_PARAM)
+int whoami_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
- if (argc > 1)
+ if (argv[1])
bb_show_usage();
/* Will complain and die if username not found */
View
@@ -835,7 +835,7 @@ static action*** parse_params(char **argv)
int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int find_main(int argc, char **argv)
+int find_main(int argc UNUSED_PARAM, char **argv)
{
static const char options[] ALIGN1 =
"-follow\0"
@@ -859,7 +859,7 @@ IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
INIT_G();
- for (firstopt = 1; firstopt < argc; firstopt++) {
+ for (firstopt = 1; argv[firstopt]; firstopt++) {
if (argv[firstopt][0] == '-')
break;
if (ENABLE_FEATURE_FIND_NOT && LONE_CHAR(argv[firstopt], '!'))
View
@@ -519,7 +519,7 @@ static int grep_dir(const char *dir)
}
int grep_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int grep_main(int argc, char **argv)
+int grep_main(int argc UNUSED_PARAM, char **argv)
{
FILE *file;
int matched;
@@ -606,7 +606,6 @@ int grep_main(int argc, char **argv)
}
argv += optind;
- argc -= optind;
/* if we didn't get a pattern from -e and no command file was specified,
* first parameter should be the pattern. no pattern, no worky */
@@ -616,12 +615,11 @@ int grep_main(int argc, char **argv)
bb_show_usage();
pattern = new_grep_list_data(*argv++, 0);
llist_add_to(&pattern_head, pattern);
- argc--;
}
/* argv[0..(argc-1)] should be names of file to grep through. If
* there is more than one file to grep, we will print the filenames. */
- if (argc > 1)
+ if (argv[0] && argv[1])
print_filename = 1;
/* -H / -h of course override */
if (option_mask32 & OPT_H)
@@ -633,7 +631,7 @@ int grep_main(int argc, char **argv)
* stdin. Otherwise, we grep through all the files specified. */
matched = 0;
do {
- cur_file = *argv++;
+ cur_file = *argv;
file = stdin;
if (!cur_file || LONE_DASH(cur_file)) {
cur_file = "(standard input)";
@@ -659,7 +657,7 @@ int grep_main(int argc, char **argv)
matched += grep_file(file);
fclose_if_not_stdin(file);
grep_done: ;
- } while (--argc > 0);
+ } while (*argv && *++argv);
/* destroy all the elments in the pattern list */
if (ENABLE_FEATURE_CLEAN_UP) {
View
@@ -16,21 +16,23 @@
#endif
int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int mesg_main(int argc, char **argv)
+int mesg_main(int argc UNUSED_PARAM, char **argv)
{
struct stat sb;
const char *tty;
char c = 0;
- if (--argc == 0
- || (argc == 1 && ((c = **++argv) == 'y' || c == 'n'))
+ argv++;
+
+ if (!argv[0]
+ || (!argv[1] && ((c = argv[0][0]) == 'y' || c == 'n'))
) {
tty = xmalloc_ttyname(STDERR_FILENO);
if (tty == NULL) {
tty = "ttyname";
} else if (stat(tty, &sb) == 0) {
mode_t m;
- if (argc == 0) {
+ if (c == 0) {
puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
return EXIT_SUCCESS;
}
View
@@ -35,7 +35,7 @@
#endif
int last_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int last_main(int argc, char **argv UNUSED_PARAM)
+int last_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
struct utmp ut;
int n, file = STDIN_FILENO;
@@ -56,7 +56,7 @@ int last_main(int argc, char **argv UNUSED_PARAM)
TYPE_OLD_TIME /* OLD_TIME, 4 */
};
- if (argc > 1) {
+ if (argv[1]) {
bb_show_usage();
}
file = xopen(bb_path_wtmp_file, O_RDONLY);
View
@@ -13,11 +13,13 @@
#include "libbb.h"
int readahead_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int readahead_main(int argc, char **argv)
+int readahead_main(int argc UNUSED_PARAM, char **argv)
{
int retval = EXIT_SUCCESS;
- if (argc == 1) bb_show_usage();
+ if (!argv[1]) {
+ bb_show_usage();
+ }
while (*++argv) {
int fd = open_or_warn(*argv, O_RDONLY);
View
@@ -12,7 +12,7 @@
#include "libbb.h"
int ttysize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int ttysize_main(int argc, char **argv)
+int ttysize_main(int argc UNUSED_PARAM, char **argv)
{
unsigned w, h;
struct winsize wsz;
@@ -24,7 +24,7 @@ int ttysize_main(int argc, char **argv)
h = wsz.ws_row;
}
- if (argc == 1) {
+ if (!argv[1]) {
printf("%u %u", w, h);
} else {
const char *fmt, *arg;
View
@@ -260,7 +260,7 @@ static int in_ether(const char *bufp, struct sockaddr *sap);
* Our main function.
*/
int ifconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int ifconfig_main(int argc, char **argv)
+int ifconfig_main(int argc UNUSED_PARAM, char **argv)
{
struct ifreq ifr;
struct sockaddr_in sai;
@@ -291,19 +291,17 @@ int ifconfig_main(int argc, char **argv)
/* skip argv[0] */
++argv;
- --argc;
#if ENABLE_FEATURE_IFCONFIG_STATUS
- if (argc > 0 && (argv[0][0] == '-' && argv[0][1] == 'a' && !argv[0][2])) {
+ if (argv[0] && (argv[0][0] == '-' && argv[0][1] == 'a' && !argv[0][2])) {
interface_opt_a = 1;
- --argc;
++argv;
}
#endif
- if (argc <= 1) {
+ if (!argv[0] || !argv[1]) { /* one or no args */
#if ENABLE_FEATURE_IFCONFIG_STATUS
- return display_interfaces(argc ? *argv : NULL);
+ return display_interfaces(argv[0] /* can be NULL */);
#else
bb_error_msg_and_die("no support for status display");
#endif
View
@@ -1142,7 +1142,7 @@ static llist_t *read_iface_state(void)
int ifupdown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int ifupdown_main(int argc, char **argv)
+int ifupdown_main(int argc UNUSED_PARAM, char **argv)
{
int (*cmds)(struct interface_defn_t *);
struct interfaces_file_t *defn;
@@ -1161,7 +1161,8 @@ int ifupdown_main(int argc, char **argv)
}
getopt32(argv, OPTION_STR, &interfaces);
- if (argc - optind > 0) {
+ argv += optind;
+ if (argv[0]) {
if (DO_ALL) bb_show_usage();
} else {
if (!DO_ALL) bb_show_usage();
@@ -1175,7 +1176,7 @@ int ifupdown_main(int argc, char **argv)
if (DO_ALL) {
target_list = defn->autointerfaces;
} else {
- llist_add_to_end(&target_list, argv[optind]);
+ llist_add_to_end(&target_list, argv[0]);
}
/* Update the interfaces */
View
@@ -673,7 +673,7 @@ Debug("wrote %d to net, errno %d", rr, errno);
/* main: now we pull it all together... */
int nc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int nc_main(int argc, char **argv)
+int nc_main(int argc UNUSED_PARAM, char **argv)
{
char *str_p, *str_s;
IF_NC_EXTRA(char *str_i, *str_o;)
@@ -702,7 +702,6 @@ int nc_main(int argc, char **argv)
while (*++proggie) {
if (strcmp(*proggie, "-e") == 0) {
*proggie = NULL;
- argc = proggie - argv;
proggie++;
goto e_found;
}
View
@@ -182,7 +182,7 @@ static ALWAYS_INLINE unsigned random_delay_ms(unsigned secs)
* main program
*/
int zcip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int zcip_main(int argc, char **argv)
+int zcip_main(int argc UNUSED_PARAM, char **argv)
{
int state;
char *r_opt;
@@ -241,7 +241,6 @@ int zcip_main(int argc, char **argv)
bb_error_msg_and_die("invalid link address");
}
}
- argc -= optind;
argv += optind - 1;
/* Now: argv[0]:junk argv[1]:intf argv[2]:script argv[3]:NULL */
Oops, something went wrong.

0 comments on commit 2ec91ae

Please sign in to comment.