aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-01-21 14:04:49 +0000
committerRon Yorston <rmy@pobox.com>2014-01-21 14:04:49 +0000
commit883817e32ce3173fdd49616b86368614e58b9354 (patch)
tree47d6ef1cfd8ae338fe52d66cfb9f8cdffdd80a2a
parentbaac891244b03eec99cf14a724ebcdc5877bd4e7 (diff)
downloadbusybox-w32-883817e32ce3173fdd49616b86368614e58b9354.tar.gz
busybox-w32-883817e32ce3173fdd49616b86368614e58b9354.tar.bz2
busybox-w32-883817e32ce3173fdd49616b86368614e58b9354.zip
date: improve emulation of %e format
-rw-r--r--win32/mingw.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 810cce604..eb0f77a28 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -803,28 +803,33 @@ int mingw_unlink(const char *pathname)
803size_t mingw_strftime(const char *buf, size_t max, const char *format, const struct tm *tm) 803size_t mingw_strftime(const char *buf, size_t max, const char *format, const struct tm *tm)
804{ 804{
805 size_t ret; 805 size_t ret;
806 const char *s; 806 char day[3];
807 char *t; 807 char *t;
808 char *fmt = NULL; 808 char *fmt;
809 809
810 /* 810 /*
811 * Provide a simple-minded emulation of the '%e' format that Windows' 811 * Emulate the '%e' format that Windows' strftime lacks. Happily, the
812 * strftime lacks. It won't work properly if there's more than one 812 * string that replaces '%e' is always two characters long.
813 * '%e' or if the user is playing games with '%'s.
814 */ 813 */
815 if ( (s=strstr(format, "%e")) != NULL ) { 814 fmt = xstrdup(format);
816 fmt = xmalloc(strlen(format)+5); 815 for ( t=fmt; *t; ++t ) {
817 strcpy(fmt, format); 816 if ( *t == '%' ) {
818 t = strstr(fmt, "%e"); 817 if ( t[1] == 'e' ) {
819 if ( tm->tm_mday < 10 ) { 818 if ( tm->tm_mday >= 0 && tm->tm_mday <= 99 ) {
820 strcat(strcpy(t, " %#d"), s+2); 819 sprintf(day, "%2d", tm->tm_mday);
821 } 820 }
822 else { 821 else {
823 t[1] = 'd'; 822 strcpy(day, " ");
823 }
824 memcpy(t++, day, 2);
825 }
826 else if ( t[1] != '\0' ) {
827 ++t;
828 }
824 } 829 }
825 } 830 }
826 831
827 ret = strftime(buf, max, fmt ? fmt : format, tm); 832 ret = strftime(buf, max, fmt, tm);
828 free(fmt); 833 free(fmt);
829 834
830 return ret; 835 return ret;