diff options
author | Ron Yorston <rmy@pobox.com> | 2014-01-19 19:45:59 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2014-01-19 19:45:59 +0000 |
commit | ae1b385859a4d1db78f077478f7aeff904d84453 (patch) | |
tree | 783395daf070ed08e573e8dee85b1f8050cd3e40 | |
parent | f0e65513106dfb105f85260a6b47383325304e5e (diff) | |
download | busybox-w32-ae1b385859a4d1db78f077478f7aeff904d84453.tar.gz busybox-w32-ae1b385859a4d1db78f077478f7aeff904d84453.tar.bz2 busybox-w32-ae1b385859a4d1db78f077478f7aeff904d84453.zip |
date: emulate %e format
-rw-r--r-- | coreutils/date.c | 8 | ||||
-rw-r--r-- | win32/mingw.c | 31 |
2 files changed, 31 insertions, 8 deletions
diff --git a/coreutils/date.c b/coreutils/date.c index 62cceff9c..4860aa308 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -328,11 +328,7 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
328 | i = sizeof("%a, %d %b %Y %H:%M:%S ")-1; | 328 | i = sizeof("%a, %d %b %Y %H:%M:%S ")-1; |
329 | goto format_utc; | 329 | goto format_utc; |
330 | } else { /* default case */ | 330 | } else { /* default case */ |
331 | #if ENABLE_PLATFORM_MINGW32 | ||
332 | fmt_dt2str = (char*)"%a %b %d %H:%M:%S %Z %Y"; | ||
333 | #else | ||
334 | fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y"; | 331 | fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y"; |
335 | #endif | ||
336 | } | 332 | } |
337 | } | 333 | } |
338 | #if ENABLE_FEATURE_DATE_NANO | 334 | #if ENABLE_FEATURE_DATE_NANO |
@@ -385,10 +381,6 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
385 | if (strncmp(fmt_dt2str, "%f", 2) == 0) { | 381 | if (strncmp(fmt_dt2str, "%f", 2) == 0) { |
386 | fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S"; | 382 | fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S"; |
387 | } | 383 | } |
388 | #if ENABLE_PLATFORM_MINGW32 | ||
389 | if (strstr(fmt_dt2str, "%e")) | ||
390 | bb_error_msg_and_die("%%e is not supported by Windows strftime"); | ||
391 | #endif | ||
392 | /* Generate output string */ | 384 | /* Generate output string */ |
393 | strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time); | 385 | strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time); |
394 | } | 386 | } |
diff --git a/win32/mingw.c b/win32/mingw.c index 70a8cb611..bbeb3b8d8 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -804,6 +804,37 @@ char *strptime(const char *s UNUSED_PARAM, const char *format UNUSED_PARAM, stru | |||
804 | return NULL; | 804 | return NULL; |
805 | } | 805 | } |
806 | 806 | ||
807 | #undef strftime | ||
808 | size_t mingw_strftime(const char *buf, size_t max, const char *format, const struct tm *tm) | ||
809 | { | ||
810 | size_t ret; | ||
811 | const char *s; | ||
812 | char *t; | ||
813 | char *fmt = NULL; | ||
814 | |||
815 | /* | ||
816 | * Provide a simple-minded emulation of the '%e' format that Windows' | ||
817 | * strftime lacks. It won't work properly if there's more than one | ||
818 | * '%e' or if the user is playing games with '%'s. | ||
819 | */ | ||
820 | if ( (s=strstr(format, "%e")) != NULL ) { | ||
821 | fmt = xmalloc(strlen(format)+5); | ||
822 | strcpy(fmt, format); | ||
823 | t = strstr(fmt, "%e"); | ||
824 | if ( tm->tm_mday < 10 ) { | ||
825 | strcat(strcpy(t, " %#d"), s+2); | ||
826 | } | ||
827 | else { | ||
828 | t[1] = 'd'; | ||
829 | } | ||
830 | } | ||
831 | |||
832 | ret = strftime(buf, max, fmt ? fmt : format, tm); | ||
833 | free(fmt); | ||
834 | |||
835 | return ret; | ||
836 | } | ||
837 | |||
807 | #undef access | 838 | #undef access |
808 | int mingw_access(const char *name, int mode) | 839 | int mingw_access(const char *name, int mode) |
809 | { | 840 | { |