adjtimex: getopt_ulflags'isation

This commit is contained in:
Denis Vlasenko 2006-09-22 08:47:54 +00:00
parent cb1ba86507
commit 109d21fe74

View File

@ -44,49 +44,44 @@ static const char * const ret_code_descript[] = {
int adjtimex_main(int argc, char **argv) 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; struct timex txc;
int quiet=0; int i, ret, sep;
int c, i, ret, sep;
const char *descript; const char *descript;
txc.modes=0; txc.modes=0;
for (;;) {
c = getopt( argc, argv, "qo:f:p:t:"); opt = bb_getopt_ulflags(argc, argv, "qo:f:p:t:",
if (c == EOF) break; &opt_o, &opt_f, &opt_p, &opt_t);
switch (c) { //if (opt & 0x1) // -q
case 'q': if (opt & 0x2) { // -o
quiet=1; txc.offset = atoi(opt_o);
break; txc.modes |= ADJ_OFFSET_SINGLESHOT;
case 'o': }
txc.offset = atoi(optarg); if (opt & 0x4) { // -f
txc.modes |= ADJ_OFFSET_SINGLESHOT; txc.freq = atoi(opt_f);
break; txc.modes |= ADJ_FREQUENCY;
case 'f': }
txc.freq = atoi(optarg); if (opt & 0x8) { // -p
txc.modes |= ADJ_FREQUENCY; txc.constant = atoi(opt_p);
break; txc.modes |= ADJ_TIMECONST;
case 'p': }
txc.constant = atoi(optarg); if (opt & 0x10) { // -t
txc.modes |= ADJ_TIMECONST; txc.tick = atoi(opt_t);
break; txc.modes |= ADJ_TICK;
case 't':
txc.tick = atoi(optarg);
txc.modes |= ADJ_TICK;
break;
default:
bb_show_usage();
exit(1);
}
} }
if (argc != optind) { /* no valid non-option parameters */ if (argc != optind) { /* no valid non-option parameters */
bb_show_usage(); bb_show_usage();
exit(1);
} }
ret = adjtimex(&txc); ret = adjtimex(&txc);
if (ret < 0) perror("adjtimex"); if (ret < 0) perror("adjtimex");
if (!quiet && ret>=0) { if (!(opt & OPT_quiet) && ret>=0) {
printf( printf(
" mode: %d\n" " mode: %d\n"
"-o offset: %ld\n" "-o offset: %ld\n"