aboutsummaryrefslogtreecommitdiff
path: root/libbb/time.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-09-21 15:19:18 +0100
committerRon Yorston <rmy@pobox.com>2021-09-21 15:19:18 +0100
commit90b3ba992ecb39e32e5a66b2e37579becc56d286 (patch)
tree4c4a2c9e1baeb8230d78efd058bb4bcabc3fd12b /libbb/time.c
parentdf34f5e92b1d10f0bb858d2ea6e8c249e87ac593 (diff)
parent56f0e886db0543a27f369d7f95eb9da2fb3d069c (diff)
downloadbusybox-w32-90b3ba992ecb39e32e5a66b2e37579becc56d286.tar.gz
busybox-w32-90b3ba992ecb39e32e5a66b2e37579becc56d286.tar.bz2
busybox-w32-90b3ba992ecb39e32e5a66b2e37579becc56d286.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/time.c')
-rw-r--r--libbb/time.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/libbb/time.c b/libbb/time.c
index ed4f50470..e7c9fa65e 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -13,6 +13,7 @@
13int FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm) 13int FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
14{ 14{
15 char end = '\0'; 15 char end = '\0';
16 time_t t;
16#if ENABLE_DESKTOP 17#if ENABLE_DESKTOP
17/* 18/*
18 * strptime is BIG: ~1k in uclibc, ~10k in glibc 19 * strptime is BIG: ~1k in uclibc, ~10k in glibc
@@ -29,10 +30,10 @@ int FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
29 "%b %d %T %Y" "\0" /* month_name d HH:MM:SS YYYY */ 30 "%b %d %T %Y" "\0" /* month_name d HH:MM:SS YYYY */
30 "%Y-%m-%d %R" "\0" /* yyyy-mm-dd HH:MM */ 31 "%Y-%m-%d %R" "\0" /* yyyy-mm-dd HH:MM */
31 "%Y-%m-%d %T" "\0" /* yyyy-mm-dd HH:MM:SS */ 32 "%Y-%m-%d %T" "\0" /* yyyy-mm-dd HH:MM:SS */
32#if ENABLE_FEATURE_TIMEZONE 33# if ENABLE_FEATURE_TIMEZONE
33 "%Y-%m-%d %R %z" "\0" /* yyyy-mm-dd HH:MM TZ */ 34 "%Y-%m-%d %R %z" "\0" /* yyyy-mm-dd HH:MM TZ */
34 "%Y-%m-%d %T %z" "\0" /* yyyy-mm-dd HH:MM:SS TZ */ 35 "%Y-%m-%d %T %z" "\0" /* yyyy-mm-dd HH:MM:SS TZ */
35#endif 36# endif
36 "%Y-%m-%d %H" "\0" /* yyyy-mm-dd HH */ 37 "%Y-%m-%d %H" "\0" /* yyyy-mm-dd HH */
37 "%Y-%m-%d" "\0" /* yyyy-mm-dd */ 38 "%Y-%m-%d" "\0" /* yyyy-mm-dd */
38 /* extra NUL */; 39 /* extra NUL */;
@@ -50,11 +51,8 @@ int FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
50 endp = strptime(date_str, fmt, ptm); 51 endp = strptime(date_str, fmt, ptm);
51#endif 52#endif
52 if (endp && *endp == '\0') { 53 if (endp && *endp == '\0') {
53#if ENABLE_FEATURE_TIMEZONE 54# if ENABLE_FEATURE_TIMEZONE
54 if (strchr(fmt, 'z')) { 55 if (strchr(fmt, 'z')) {
55 time_t t;
56 struct tm *utm;
57
58 /* we have timezone offset: obtain Unix time_t */ 56 /* we have timezone offset: obtain Unix time_t */
59#if ENABLE_PLATFORM_MINGW32 57#if ENABLE_PLATFORM_MINGW32
60 ptm->tm_sec -= gmtoff; 58 ptm->tm_sec -= gmtoff;
@@ -66,13 +64,9 @@ int FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
66 if (t == (time_t)-1) 64 if (t == (time_t)-1)
67 break; 65 break;
68 /* convert Unix time_t to struct tm in user's locale */ 66 /* convert Unix time_t to struct tm in user's locale */
69 utm = localtime(&t); 67 goto localise;
70 if (!utm)
71 break;
72 *ptm = *utm;
73 return 0;
74 } 68 }
75#endif 69# endif
76 return 1; 70 return 1;
77 } 71 }
78 *ptm = save; 72 *ptm = save;
@@ -150,13 +144,14 @@ int FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
150 } else 144 } else
151#endif /* ENABLE_DESKTOP */ 145#endif /* ENABLE_DESKTOP */
152 if (date_str[0] == '@') { 146 if (date_str[0] == '@') {
153 time_t t;
154 if (sizeof(t) <= sizeof(long)) 147 if (sizeof(t) <= sizeof(long))
155 t = bb_strtol(date_str + 1, NULL, 10); 148 t = bb_strtol(date_str + 1, NULL, 10);
156 else /* time_t is 64 bits but longs are smaller */ 149 else /* time_t is 64 bits but longs are smaller */
157 t = bb_strtoll(date_str + 1, NULL, 10); 150 t = bb_strtoll(date_str + 1, NULL, 10);
158 if (!errno) { 151 if (!errno) {
159 struct tm *lt = localtime(&t); 152 struct tm *lt;
153 IF_FEATURE_TIMEZONE(localise:)
154 lt = localtime(&t);
160 if (lt) { 155 if (lt) {
161 *ptm = *lt; 156 *ptm = *lt;
162 return 0; 157 return 0;