&(tm_time->tm_year));
if (nr < 4 || nr > 5) {
- error_msg_and_die(invalid_date, t_string);
+ bb_error_msg_and_die(bb_msg_invalid_date, t_string);
}
/* correct for century - minor Y2K problem here? */
t.tm_year -= 1900; /* Adjust years */
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
} else {
- error_msg_and_die(invalid_date, t_string);
+ bb_error_msg_and_die(bb_msg_invalid_date, t_string);
}
*tm_time = t;
return (tm_time);
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
- int c;
- int set_time = 0;
- int rfc822 = 0;
- int utc = 0;
+ int set_time;
+ int rfc822;
+ int utc;
int use_arg = 0;
time_t tm;
+ unsigned long opt;
struct tm tm_time;
#ifdef CONFIG_FEATURE_DATE_ISOFMT
int ifmt = 0;
+ char *isofmt_arg;
# define GETOPT_ISOFMT "I::"
#else
# define GETOPT_ISOFMT
#endif
-
- /* Interpret command line args */
- while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT)) != EOF) {
- switch (c) {
- case 'R':
- rfc822 = 1;
- break;
- case 's':
- set_time = 1;
- if ((date_str != NULL) || ((date_str = optarg) == NULL)) {
- show_usage();
- }
- break;
- case 'u':
- utc = 1;
+ bb_opt_complementaly = "d~ds:s~ds";
+ opt = bb_getopt_ulflags(argc, argv, "Rs:ud:" GETOPT_ISOFMT,
+ &date_str, &date_str
+#ifdef CONFIG_FEATURE_DATE_ISOFMT
+ , &isofmt_arg
+#endif
+ );
+ rfc822 = opt & 1;
+ set_time = opt & 2;
+ utc = opt & 4;
+ if(utc) {
if (putenv("TZ=UTC0") != 0)
- error_msg_and_die(memory_exhausted);
- break;
- case 'd':
- use_arg = 1;
- if ((date_str != NULL) || ((date_str = optarg) == NULL))
- show_usage();
- break;
+ bb_error_msg_and_die(bb_msg_memory_exhausted);
+ }
+ use_arg = opt & 8;
+ if(opt & 0x80000000UL)
+ bb_show_usage();
#ifdef CONFIG_FEATURE_DATE_ISOFMT
- case 'I':
- if (!optarg)
+ if(opt & 16) {
+ if (!isofmt_arg)
ifmt = 1;
else {
- int ifmt_len = xstrlen(optarg);
+ int ifmt_len = bb_strlen(isofmt_arg);
if ((ifmt_len <= 4)
- && (strncmp(optarg, "date", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "date", ifmt_len) == 0)) {
ifmt = 1;
} else if ((ifmt_len <= 5)
- && (strncmp(optarg, "hours", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) {
ifmt = 2;
} else if ((ifmt_len <= 7)
- && (strncmp(optarg, "minutes", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) {
ifmt = 3;
} else if ((ifmt_len <= 7)
- && (strncmp(optarg, "seconds", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) {
ifmt = 4;
}
}
- if (ifmt) {
- break; /* else show_usage(); */
- }
-#endif
- default:
- show_usage();
+ if (!ifmt) {
+ bb_show_usage();
}
}
-
+#endif
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
date_fmt = &argv[optind][1]; /* Skip over the '+' */
}
/* Correct any day of week and day of year etc. fields */
+ tm_time.tm_isdst = -1; /* Be sure to recheck dst. */
tm = mktime(&tm_time);
if (tm < 0) {
- error_msg_and_die(invalid_date, date_str);
+ bb_error_msg_and_die(bb_msg_invalid_date, date_str);
}
if (utc && (putenv("TZ=UTC0") != 0)) {
- error_msg_and_die(memory_exhausted);
+ bb_error_msg_and_die(bb_msg_memory_exhausted);
}
/* if setting time, set it */
if (set_time && (stime(&tm) < 0)) {
- perror_msg("cannot set date");
+ bb_perror_msg("cannot set date");
}
}