11
void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
11
/* Returns 0 if the time structure contains an absolute UTC time which
12
* should not be subject to DST adjustment by the caller. */
13
int FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
19
* strptime is BIG: ~1k in uclibc, ~10k in glibc
20
* We need it for 'month_name d HH:MM:SS YYYY', supported by GNU date,
21
* but if we've linked it we might as well use it for everything.
23
static const char fmt_str[] ALIGN1 =
25
"%T" "\0" /* HH:MM:SS */
26
"%m.%d-%R" "\0" /* mm.dd-HH:MM */
27
"%m.%d-%T" "\0" /* mm.dd-HH:MM:SS */
28
"%Y.%m.%d-%R" "\0" /* yyyy.mm.dd-HH:MM */
29
"%Y.%m.%d-%T" "\0" /* yyyy.mm.dd-HH:MM:SS */
30
"%b %d %T %Y" "\0" /* month_name d HH:MM:SS YYYY */
31
"%Y-%m-%d %R" "\0" /* yyyy-mm-dd HH:MM */
32
"%Y-%m-%d %T" "\0" /* yyyy-mm-dd HH:MM:SS */
33
# if ENABLE_FEATURE_TIMEZONE
34
"%Y-%m-%d %R %z" "\0" /* yyyy-mm-dd HH:MM TZ */
35
"%Y-%m-%d %T %z" "\0" /* yyyy-mm-dd HH:MM:SS TZ */
37
"%Y-%m-%d %H" "\0" /* yyyy-mm-dd HH */
38
"%Y-%m-%d" "\0" /* yyyy-mm-dd */
47
endp = strptime(date_str, fmt, ptm);
48
if (endp && *endp == '\0') {
49
# if ENABLE_FEATURE_TIMEZONE
50
if (strchr(fmt, 'z')) {
51
/* we have timezone offset: obtain Unix time_t */
52
ptm->tm_sec -= ptm->tm_gmtoff;
57
/* convert Unix time_t to struct tm in user's locale */
14
69
const char *last_colon = strrchr(date_str, ':');
16
71
if (last_colon != NULL) {
17
72
/* Parse input and assign appropriately to ptm */
23
75
if (sscanf(date_str, "%u:%u%c",
50
102
ptm->tm_year -= 1900; /* Adjust years */
51
103
ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
53
#if ENABLE_DESKTOP /* strptime is BIG: ~1k in uclibc, ~10k in glibc */
54
/* month_name d HH:MM:SS YYYY. Supported by GNU date */
55
if ((endp = strptime(date_str, "%b %d %T %Y", ptm)) != NULL
58
return; /* don't fall through to end == ":" check */
62
106
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
89
133
ptm->tm_year -= 1900; /* Adjust years */
90
134
ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
136
#endif /* ENABLE_DESKTOP */
92
137
if (date_str[0] == '@') {
93
time_t t = bb_strtol(date_str + 1, NULL, 10);
138
if (sizeof(t) <= sizeof(long))
139
t = bb_strtol(date_str + 1, NULL, 10);
140
else /* time_t is 64 bits but longs are smaller */
141
t = bb_strtoll(date_str + 1, NULL, 10);
95
struct tm *lt = localtime(&t);
144
IF_FEATURE_TIMEZONE(localise:)
288
338
unsigned long long FAST_FUNC monotonic_ns(void)
290
340
struct timeval tv;
291
gettimeofday(&tv, NULL);
292
342
return tv.tv_sec * 1000000000ULL + tv.tv_usec * 1000;
294
344
unsigned long long FAST_FUNC monotonic_us(void)
296
346
struct timeval tv;
297
gettimeofday(&tv, NULL);
298
348
return tv.tv_sec * 1000000ULL + tv.tv_usec;
300
350
unsigned long long FAST_FUNC monotonic_ms(void)
302
352
struct timeval tv;
303
gettimeofday(&tv, NULL);
304
354
return tv.tv_sec * 1000ULL + tv.tv_usec / 1000;
306
356
unsigned FAST_FUNC monotonic_sec(void)