Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/time.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/libbb/time.c

    r3232 r3621  
    2424                    &ptm->tm_hour,
    2525                    &ptm->tm_min,
    26                     &end) >= 2) {
     26                    &end) >= 2
     27        ) {
    2728            /* no adjustments needed */
    2829        } else
     
    3132                    &ptm->tm_mon, &ptm->tm_mday,
    3233                    &ptm->tm_hour, &ptm->tm_min,
    33                     &end) >= 4) {
     34                    &end) >= 4
     35        ) {
    3436            /* Adjust month from 1-12 to 0-11 */
    3537            ptm->tm_mon -= 1;
     
    3941                    &ptm->tm_mon, &ptm->tm_mday,
    4042                    &ptm->tm_hour, &ptm->tm_min,
    41                     &end) >= 5) {
    42             ptm->tm_year -= 1900; /* Adjust years */
    43             ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
    44         } else
     43                    &end) >= 5
    4544        /* yyyy-mm-dd HH:MM */
    46         if (sscanf(date_str, "%u-%u-%u %u:%u%c", &ptm->tm_year,
     45         || sscanf(date_str, "%u-%u-%u %u:%u%c", &ptm->tm_year,
    4746                    &ptm->tm_mon, &ptm->tm_mday,
    4847                    &ptm->tm_hour, &ptm->tm_min,
    49                     &end) >= 5) {
     48                    &end) >= 5
     49        ) {
    5050            ptm->tm_year -= 1900; /* Adjust years */
    5151            ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
     
    5959        } else
    6060#endif
    61 //TODO: coreutils 6.9 also accepts "yyyy-mm-dd HH" (no minutes)
    6261        {
    6362            bb_error_msg_and_die(bb_msg_invalid_date, date_str);
     
    6968            /* else end != NUL and we error out */
    7069        }
    71     } else if (date_str[0] == '@') {
     70    } else
     71    if (strchr(date_str, '-')
     72        /* Why strchr('-') check?
     73         * sscanf below will trash ptm->tm_year, this breaks
     74         * if parse_str is "10101010" (iow, "MMddhhmm" form)
     75         * because we destroy year. Do these sscanf
     76         * only if we saw a dash in parse_str.
     77         */
     78        /* yyyy-mm-dd HH */
     79     && (sscanf(date_str, "%u-%u-%u %u%c", &ptm->tm_year,
     80                &ptm->tm_mon, &ptm->tm_mday,
     81                &ptm->tm_hour,
     82                &end) >= 4
     83        /* yyyy-mm-dd */
     84         || sscanf(date_str, "%u-%u-%u%c", &ptm->tm_year,
     85                &ptm->tm_mon, &ptm->tm_mday,
     86                &end) >= 3
     87        )
     88    ) {
     89        ptm->tm_year -= 1900; /* Adjust years */
     90        ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
     91    } else
     92    if (date_str[0] == '@') {
    7293        time_t t = bb_strtol(date_str + 1, NULL, 10);
    7394        if (!errno) {
     
    166187            bb_error_msg_and_die(bb_msg_invalid_date, date_str);
    167188        }
     189        ptm->tm_sec = 0; /* assume zero if [.SS] is not given */
    168190        if (end == '.') {
    169191            /* xxx.SS */
     
    188210}
    189211
     212static char* strftime_fmt(char *buf, unsigned len, time_t *tp, const char *fmt)
     213{
     214    time_t t;
     215    if (!tp) {
     216        tp = &t;
     217        time(tp);
     218    }
     219    /* Returns pointer to NUL */
     220    return buf + strftime(buf, len, fmt, localtime(tp));
     221}
     222
     223char* FAST_FUNC strftime_HHMMSS(char *buf, unsigned len, time_t *tp)
     224{
     225    return strftime_fmt(buf, len, tp, "%H:%M:%S");
     226}
     227
     228char* FAST_FUNC strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp)
     229{
     230    return strftime_fmt(buf, len, tp, "%Y-%m-%d %H:%M:%S");
     231}
     232
    190233#if ENABLE_MONOTONIC_SYSCALL
    191234
Note: See TracChangeset for help on using the changeset viewer.