Changes in / [8595b954:ce1df04] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/date/date.c

    r8595b954 rce1df04  
    4141static int read_date_from_arg(char *wdate, struct tm *t);
    4242static int read_time_from_arg(char *wdate, struct tm *t);
     43static int read_num_from_str(char *str, size_t len, int *n);
    4344static int tm_sanity_check(struct tm *t);
    4445static bool is_leap_year(int year);
     
    201202{
    202203        int rc;
    203         uint32_t tmp;
    204204
    205205        if (str_size(wdate) != 10) /* str_size("DD/MM/YYYY") == 10 */
     
    211211        }
    212212
    213         rc = str_uint32_t(&wdate[0], NULL, 10, false, &tmp);
     213        rc = read_num_from_str(&wdate[0], 2, &t->tm_mday);
    214214        if (rc != EOK)
    215215                return rc;
    216216
    217         t->tm_mday = tmp;
    218 
    219         rc = str_uint32_t(&wdate[3], NULL, 10, false, &tmp);
     217        rc = read_num_from_str(&wdate[3], 2, &t->tm_mon);
    220218        if (rc != EOK)
    221219                return rc;
    222 
    223         t->tm_mon = tmp - 1;
    224 
    225         rc = str_uint32_t(&wdate[6], NULL, 10, false, &tmp);
    226         t->tm_year = tmp - 1900;
    227 
     220        t->tm_mon--;
     221
     222        rc = read_num_from_str(&wdate[6], 4, &t->tm_year);
     223        t->tm_year -= 1900;
    228224        return rc;
    229225}
     
    238234        size_t len = str_size(wtime);
    239235        bool sec_present = len == 8;
    240         uint32_t tmp;
    241236
    242237        /* str_size("HH:MM") == 5 */
     
    251246                return EINVAL;
    252247
    253         rc = str_uint32_t(&wtime[0], NULL, 10, false, &tmp);
     248        rc = read_num_from_str(&wtime[0], 2, &t->tm_hour);
    254249        if (rc != EOK)
    255250                return rc;
    256251
    257         t->tm_hour = tmp;
    258 
    259         rc = str_uint32_t(&wtime[3], NULL, 10, false, &tmp);
     252        rc = read_num_from_str(&wtime[3], 2, &t->tm_min);
    260253        if (rc != EOK)
    261254                return rc;
    262255
    263         t->tm_min = tmp;
    264 
    265         if (sec_present) {
    266                 rc = str_uint32_t(&wtime[6], NULL, 10, false, &tmp);
    267                 t->tm_sec = tmp;
    268         } else
     256        if (sec_present)
     257                rc = read_num_from_str(&wtime[6], 2, &t->tm_sec);
     258        else
    269259                t->tm_sec = 0;
    270260
    271261        return rc;
     262}
     263
     264static int
     265read_num_from_str(char *str, size_t len, int *n)
     266{
     267        size_t i;
     268
     269        *n = 0;
     270
     271        for (i = 0; i < len; ++i, ++str) {
     272                if (!isdigit(*str))
     273                        return EINVAL;
     274                *n *= 10;
     275                *n += *str - '0';
     276        }
     277
     278        return EOK;
    272279}
    273280
Note: See TracChangeset for help on using the changeset viewer.