Changeset df7f9fb5 in mainline


Ignore:
Timestamp:
2012-09-18T19:21:16Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0a586f4c, 8595b954
Parents:
7137fe3f
Message:

date: get rid of read_num_from_str() and use str_uint32_t instead

File:
1 edited

Legend:

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

    r7137fe3f rdf7f9fb5  
    4141static int read_date_from_arg(char *wdate, struct tm *t);
    4242static int read_time_from_arg(char *wdate, struct tm *t);
    43 static int read_num_from_str(char *str, size_t len, int *n);
    4443static int tm_sanity_check(struct tm *t);
    4544static bool is_leap_year(int year);
     
    202201{
    203202        int rc;
     203        uint32_t tmp;
    204204
    205205        if (str_size(wdate) != 10) /* str_size("DD/MM/YYYY") == 10 */
     
    211211        }
    212212
    213         rc = read_num_from_str(&wdate[0], 2, &t->tm_mday);
     213        rc = str_uint32_t(&wdate[0], NULL, 10, false, &tmp);
    214214        if (rc != EOK)
    215215                return rc;
    216216
    217         rc = read_num_from_str(&wdate[3], 2, &t->tm_mon);
     217        t->tm_mday = tmp;
     218
     219        rc = str_uint32_t(&wdate[3], NULL, 10, false, &tmp);
    218220        if (rc != EOK)
    219221                return rc;
    220         t->tm_mon--;
    221 
    222         rc = read_num_from_str(&wdate[6], 4, &t->tm_year);
    223         t->tm_year -= 1900;
     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
    224228        return rc;
    225229}
     
    234238        size_t len = str_size(wtime);
    235239        bool sec_present = len == 8;
     240        uint32_t tmp;
    236241
    237242        /* str_size("HH:MM") == 5 */
     
    246251                return EINVAL;
    247252
    248         rc = read_num_from_str(&wtime[0], 2, &t->tm_hour);
     253        rc = str_uint32_t(&wtime[0], NULL, 10, false, &tmp);
    249254        if (rc != EOK)
    250255                return rc;
    251256
    252         rc = read_num_from_str(&wtime[3], 2, &t->tm_min);
     257        t->tm_hour = tmp;
     258
     259        rc = str_uint32_t(&wtime[3], NULL, 10, false, &tmp);
    253260        if (rc != EOK)
    254261                return rc;
    255262
    256         if (sec_present)
    257                 rc = read_num_from_str(&wtime[6], 2, &t->tm_sec);
    258         else
     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
    259269                t->tm_sec = 0;
    260270
    261271        return rc;
    262 }
    263 
    264 static int
    265 read_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;
    279272}
    280273
Note: See TracChangeset for help on using the changeset viewer.