diff options
author | Mark Whitley <markw@lineo.com> | 2000-07-20 23:06:27 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2000-07-20 23:06:27 +0000 |
commit | 1ac435c15e23ae1bdd87d2b77754b6f6eb159bee (patch) | |
tree | 2640cac810cd352680265029fb21235122181780 | |
parent | 51154bacbe34d160f089c4ab4bbb51766030233d (diff) | |
download | busybox-1ac435c15e23ae1bdd87d2b77754b6f6eb159bee.tar.gz |
Converted option parsing to getopt(). Also added some explanatory comments.
-rw-r--r-- | miscutils/update.c | 27 | ||||
-rw-r--r-- | update.c | 27 |
2 files changed, 28 insertions, 26 deletions
diff --git a/miscutils/update.c b/miscutils/update.c index 0bdc90eaa..3f3d68b87 100644 --- a/miscutils/update.c +++ b/miscutils/update.c @@ -23,16 +23,22 @@ * */ +/* + * Note: This program is only necessary if you are running a 2.0.x (or + * earlier) kernel. 2.2.x and higher flush filesystem buffers automatically. + */ + #include "internal.h" #include <sys/param.h> #include <sys/syslog.h> +#include <unistd.h> /* for getopt() */ #if defined(__GLIBC__) #include <sys/kdaemon.h> #else static _syscall2(int, bdflush, int, func, int, data); -#endif /* __GLIBC__ */ +#endif /* __GLIBC__ */ static unsigned int sync_duration = 30; static unsigned int flush_duration = 5; @@ -41,29 +47,22 @@ static int use_sync = 0; extern int update_main(int argc, char **argv) { int pid; + int opt; - argc--; - argv++; - while (argc>0 && **argv == '-') { - while (*++(*argv)) { - switch (**argv) { + while ((opt = getopt(argc, argv, "Ss:f:")) > 0) { + switch (opt) { case 'S': use_sync = 1; break; case 's': - if (--argc < 1) usage(update_usage); - sync_duration = atoi(*(++argv)); + sync_duration = atoi(optarg); break; case 'f': - if (--argc < 1) usage(update_usage); - flush_duration = atoi(*(++argv)); + flush_duration = atoi(optarg); break; default: usage(update_usage); - } } - argc--; - argv++; } pid = fork(); @@ -79,6 +78,8 @@ extern int update_main(int argc, char **argv) * This is no longer necessary since 1.3.5x, but it will harmlessly * exit if that is the case. */ + + /* set the program name that will show up in a 'ps' listing */ argv[0] = "bdflush (update)"; argv[1] = NULL; argv[2] = NULL; @@ -23,16 +23,22 @@ * */ +/* + * Note: This program is only necessary if you are running a 2.0.x (or + * earlier) kernel. 2.2.x and higher flush filesystem buffers automatically. + */ + #include "internal.h" #include <sys/param.h> #include <sys/syslog.h> +#include <unistd.h> /* for getopt() */ #if defined(__GLIBC__) #include <sys/kdaemon.h> #else static _syscall2(int, bdflush, int, func, int, data); -#endif /* __GLIBC__ */ +#endif /* __GLIBC__ */ static unsigned int sync_duration = 30; static unsigned int flush_duration = 5; @@ -41,29 +47,22 @@ static int use_sync = 0; extern int update_main(int argc, char **argv) { int pid; + int opt; - argc--; - argv++; - while (argc>0 && **argv == '-') { - while (*++(*argv)) { - switch (**argv) { + while ((opt = getopt(argc, argv, "Ss:f:")) > 0) { + switch (opt) { case 'S': use_sync = 1; break; case 's': - if (--argc < 1) usage(update_usage); - sync_duration = atoi(*(++argv)); + sync_duration = atoi(optarg); break; case 'f': - if (--argc < 1) usage(update_usage); - flush_duration = atoi(*(++argv)); + flush_duration = atoi(optarg); break; default: usage(update_usage); - } } - argc--; - argv++; } pid = fork(); @@ -79,6 +78,8 @@ extern int update_main(int argc, char **argv) * This is no longer necessary since 1.3.5x, but it will harmlessly * exit if that is the case. */ + + /* set the program name that will show up in a 'ps' listing */ argv[0] = "bdflush (update)"; argv[1] = NULL; argv[2] = NULL; |