From: Mark Whitley Date: Fri, 9 Mar 2001 21:49:12 +0000 (-0000) Subject: Applied patch from Jeff Garzik to getopt-ify rmmod. X-Git-Tag: 0_50~75 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f90c28dd1ee28c29dc0f7bb4d3681f5606843793;p=oweals%2Fbusybox.git Applied patch from Jeff Garzik to getopt-ify rmmod. --- diff --git a/modutils/rmmod.c b/modutils/rmmod.c index aab326123..36857e02c 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include "busybox.h" @@ -37,15 +38,11 @@ _syscall1(int, delete_module, const char *, name) extern int rmmod_main(int argc, char **argv) { - int ret = EXIT_SUCCESS; - if (argc <= 1) { - show_usage(); - } + int n, ret = EXIT_SUCCESS; - /* Parse any options */ - while (--argc > 0 && **(++argv) == '-') { - while (*(++(*argv))) { - switch (**argv) { + /* Parse command line. */ + while ((n = getopt(argc, argv, "a")) != EOF) { + switch (n) { case 'a': /* Unload _all_ unused modules via NULL delete_module() call */ if (delete_module(NULL)) @@ -53,16 +50,18 @@ extern int rmmod_main(int argc, char **argv) return EXIT_SUCCESS; default: show_usage(); - } } } - while (argc-- > 0) { - if (delete_module(*argv) < 0) { - perror_msg("%s", *argv); + if (optind == argc) + show_usage(); + + for (n = optind; n < argc; n++) { + if (delete_module(argv[n]) < 0) { + perror_msg("%s", argv[n]); ret = EXIT_FAILURE; } - argv++; } + return(ret); } diff --git a/rmmod.c b/rmmod.c index aab326123..36857e02c 100644 --- a/rmmod.c +++ b/rmmod.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include "busybox.h" @@ -37,15 +38,11 @@ _syscall1(int, delete_module, const char *, name) extern int rmmod_main(int argc, char **argv) { - int ret = EXIT_SUCCESS; - if (argc <= 1) { - show_usage(); - } + int n, ret = EXIT_SUCCESS; - /* Parse any options */ - while (--argc > 0 && **(++argv) == '-') { - while (*(++(*argv))) { - switch (**argv) { + /* Parse command line. */ + while ((n = getopt(argc, argv, "a")) != EOF) { + switch (n) { case 'a': /* Unload _all_ unused modules via NULL delete_module() call */ if (delete_module(NULL)) @@ -53,16 +50,18 @@ extern int rmmod_main(int argc, char **argv) return EXIT_SUCCESS; default: show_usage(); - } } } - while (argc-- > 0) { - if (delete_module(*argv) < 0) { - perror_msg("%s", *argv); + if (optind == argc) + show_usage(); + + for (n = optind; n < argc; n++) { + if (delete_module(argv[n]) < 0) { + perror_msg("%s", argv[n]); ret = EXIT_FAILURE; } - argv++; } + return(ret); }