#define DATE_OPT_TIMESPEC 0x20
#define DATE_OPT_HINT 0x40
-static void maybe_set_utc(int opt)
+static void xputenv(char *s)
{
- if ((opt & DATE_OPT_UTC) && putenv("TZ=UTC0") != 0)
+ if (putenv(s) != 0)
bb_error_msg_and_die(bb_msg_memory_exhausted);
}
+static void maybe_set_utc(int opt)
+{
+ if (opt & DATE_OPT_UTC)
+ xputenv((char*)"TZ=UTC0");
+}
+
+int date_main(int argc, char **argv);
int date_main(int argc, char **argv)
{
time_t tm;
struct tm tm_time;
- unsigned long opt;
+ unsigned opt;
int ifmt = -1;
char *date_str = NULL;
char *date_fmt = NULL;
char *isofmt_arg;
char *hintfmt_arg;
- bb_opt_complementally = "?:d--s:s--d"
+ opt_complementary = "?:d--s:s--d"
USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
- opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:"
- USE_FEATURE_DATE_ISOFMT("I::D:"),
- &date_str, &date_str, &filename
- USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &hintfmt_arg));
+ opt = getopt32(argc, argv, "Rs:ud:r:"
+ USE_FEATURE_DATE_ISOFMT("I::D:"),
+ &date_str, &date_str, &filename
+ USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &hintfmt_arg));
maybe_set_utc(opt);
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_TIMESPEC)) {
if (!isofmt_arg) {
ifmt = 0; /* default is date */
} else {
- const char * const isoformats[] =
- {"date", "hours", "minutes", "seconds"};
+ static const char * const isoformats[] =
+ { "date", "hours", "minutes", "seconds" };
for (ifmt = 0; ifmt < 4; ifmt++)
- if (!strcmp(isofmt_arg, isoformats[ifmt])) {
- break;
- }
- if (ifmt == 4) /* parse error */
- bb_show_usage();
+ if (!strcmp(isofmt_arg, isoformats[ifmt]))
+ goto found;
+ /* parse error */
+ bb_show_usage();
+ found: ;
}
}
date_fmt[i++] = '%';
date_fmt[i++] = 'S';
}
-format_utc:
+ format_utc:
date_fmt[i++] = '%';
date_fmt[i] = (opt & DATE_OPT_UTC) ? 'Z' : 'z';
}
} else if (opt & DATE_OPT_RFC2822) {
+ /* Undo busybox.c for date -R */
+ if (ENABLE_LOCALE_SUPPORT)
+ setlocale(LC_TIME, "C");
strcpy(date_fmt, "%a, %d %b %Y %H:%M:%S ");
i = 22;
goto format_utc;
} else /* default case */
- date_fmt = "%a %b %e %H:%M:%S %Z %Y";
+ date_fmt = (char*)"%a %b %e %H:%M:%S %Z %Y";
}
if (*date_fmt == '\0') {
/* Handle special conversions */
if (strncmp(date_fmt, "%f", 2) == 0) {
- date_fmt = "%Y.%m.%d-%H:%M:%S";
+ date_fmt = (char*)"%Y.%m.%d-%H:%M:%S";
}
/* Generate output string */