- add libbb function str_tolower to convert a string to lowercase.
[oweals/busybox.git] / coreutils / date.c
index 37ccfd5ba45d780b4e08c02a6ed5493414d8886a..d2d77f413fc0d9b32b6ac1a725998fa17c1d2085 100644 (file)
@@ -41,9 +41,10 @@ static void xputenv(char *s)
 static void maybe_set_utc(int opt)
 {
        if (opt & DATE_OPT_UTC)
-               xputenv("TZ=UTC0");
+               xputenv((char*)"TZ=UTC0");
 }
 
+int date_main(int argc, char **argv);
 int date_main(int argc, char **argv)
 {
        time_t tm;
@@ -68,15 +69,15 @@ int date_main(int argc, char **argv)
                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: ;
                }
        }
 
@@ -206,18 +207,19 @@ int date_main(int argc, char **argv)
                                        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 */
-                       setlocale(LC_TIME, "C");
+                       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') {
@@ -227,7 +229,7 @@ format_utc:
                /* 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 */