accidentally applied wrong (old) patch, fixing up...
[oweals/busybox.git] / miscutils / adjtimex.c
index 905b80f47672fbdf9d73a2e68104cbf94fe88c3d..b35538a84114ff72b9e5953c7287995755cf5ece 100644 (file)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * adjtimex.c - read, and possibly modify, the Linux kernel `timex' variables.
  *
@@ -6,16 +7,12 @@
  * Copyright 1997, 2000, 2001 Larry Doolittle <LRDoolittle@lbl.gov>
  *
  * busyboxed 20 March 2001, Larry Doolittle <ldoolitt@recycle.lbl.gov>
- * 
+ *
  * Licensed under GPLv2 or later, see file License in this tarball for details.
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/timex.h>
 #include "busybox.h"
+#include <sys/timex.h>
 
 static const struct {int bit; const char *name;} statlist[] = {
        { STA_PLL,       "PLL"       },
@@ -43,49 +40,44 @@ static const char * const ret_code_descript[] = {
 
 int adjtimex_main(int argc, char **argv)
 {
+       enum {
+               OPT_quiet = 0x1
+       };
+       unsigned 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 = getopt32(argc, argv, "qo:f:p:t:",
+                       &opt_o, &opt_f, &opt_p, &opt_t);
+       //if (opt & 0x1) // -q
+       if (opt & 0x2) { // -o
+               txc.offset = xatoi(opt_o);
+               txc.modes |= ADJ_OFFSET_SINGLESHOT;
+       }
+       if (opt & 0x4) { // -f
+               txc.freq = xatou(opt_f);
+               txc.modes |= ADJ_FREQUENCY;
+       }
+       if (opt & 0x8) { // -p
+               txc.constant = xatoi(opt_p);
+               txc.modes |= ADJ_TIMECONST;
+       }
+       if (opt & 0x10) { // -t
+               txc.tick = xatoi(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"