summaryrefslogtreecommitdiff
path: root/miscutils/adjtimex.c
diff options
context:
space:
mode:
authorDenis Vlasenko2006-09-22 08:47:54 +0000
committerDenis Vlasenko2006-09-22 08:47:54 +0000
commit109d21fe7420fedbda7e1cd7ceb6ff2f3b59b8f1 (patch)
tree84253684e83663be63293af588309b08263c5ae0 /miscutils/adjtimex.c
parentcb1ba865077720087d47895d4125474ccbf366cc (diff)
downloadbusybox-109d21fe7420fedbda7e1cd7ceb6ff2f3b59b8f1.zip
busybox-109d21fe7420fedbda7e1cd7ceb6ff2f3b59b8f1.tar.gz
adjtimex: getopt_ulflags'isation
Diffstat (limited to 'miscutils/adjtimex.c')
-rw-r--r--miscutils/adjtimex.c57
1 files changed, 26 insertions, 31 deletions
diff --git a/miscutils/adjtimex.c b/miscutils/adjtimex.c
index abd0618..9662bbe 100644
--- a/miscutils/adjtimex.c
+++ b/miscutils/adjtimex.c
@@ -44,49 +44,44 @@ static const char * const ret_code_descript[] = {
int adjtimex_main(int argc, char **argv)
{
+ enum {
+ OPT_quiet = 0x1
+ };
+ unsigned long opt;
+ char *opt_o, *opt_f, *opt_p, *opt_t;
struct timex txc;
- int quiet=0;
- int c, i, ret, sep;
+ int i, ret, sep;
const char *descript;
txc.modes=0;
- for (;;) {
- c = getopt( argc, argv, "qo:f:p:t:");
- if (c == EOF) break;
- switch (c) {
- case 'q':
- quiet=1;
- break;
- case 'o':
- txc.offset = atoi(optarg);
- txc.modes |= ADJ_OFFSET_SINGLESHOT;
- break;
- case 'f':
- txc.freq = atoi(optarg);
- txc.modes |= ADJ_FREQUENCY;
- break;
- case 'p':
- txc.constant = atoi(optarg);
- txc.modes |= ADJ_TIMECONST;
- break;
- case 't':
- txc.tick = atoi(optarg);
- txc.modes |= ADJ_TICK;
- break;
- default:
- bb_show_usage();
- exit(1);
- }
+
+ opt = bb_getopt_ulflags(argc, argv, "qo:f:p:t:",
+ &opt_o, &opt_f, &opt_p, &opt_t);
+ //if (opt & 0x1) // -q
+ if (opt & 0x2) { // -o
+ txc.offset = atoi(opt_o);
+ txc.modes |= ADJ_OFFSET_SINGLESHOT;
+ }
+ if (opt & 0x4) { // -f
+ txc.freq = atoi(opt_f);
+ txc.modes |= ADJ_FREQUENCY;
+ }
+ if (opt & 0x8) { // -p
+ txc.constant = atoi(opt_p);
+ txc.modes |= ADJ_TIMECONST;
+ }
+ if (opt & 0x10) { // -t
+ txc.tick = atoi(opt_t);
+ txc.modes |= ADJ_TICK;
}
if (argc != optind) { /* no valid non-option parameters */
bb_show_usage();
- exit(1);
}
ret = adjtimex(&txc);
if (ret < 0) perror("adjtimex");
- if (!quiet && ret>=0) {
+ if (!(opt & OPT_quiet) && ret>=0) {
printf(
" mode: %d\n"
"-o offset: %ld\n"