Changes in / [4cade47:86e81a9] in mainline


Ignore:
Location:
uspace/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/sys/time.h

    r4cade47 r86e81a9  
    11/*
    22 * Copyright (c) 2006 Ondrej Palkovsky
    3  * Copyright (c) 2011 Petr Koupy
    4  * Copyright (c) 2011 Jiri Zarevucky
    53 * All rights reserved.
    64 *
     
    4947
    5048struct tm {
    51         int tm_sec;         /* Seconds [0,60]. */
    52         int tm_min;         /* Minutes [0,59]. */
    53         int tm_hour;        /* Hour [0,23]. */
    54         int tm_mday;        /* Day of month [1,31]. */
    55         int tm_mon;         /* Month of year [0,11]. */
    56         int tm_year;        /* Years since 1900. */
    57         int tm_wday;        /* Day of week [0,6] (Sunday = 0). */
    58         int tm_yday;        /* Day of year [0,365]. */
    59         int tm_isdst;       /* Daylight Savings flag. */
     49        int tm_sec;       /* 0 - 59 */
     50        int tm_min;       /* 0 - 59 */
     51        int tm_hour;      /* 0 - 23 */
     52        int tm_mday;      /* 1 - 31 */
     53        int tm_mon;       /* 0 - 11 */
     54        int tm_year;      /* years since 1900 */
    6055};
    6156
  • uspace/lib/posix/time.c

    r4cade47 r86e81a9  
    200200 * @return Number of seconds since the epoch, not counting leap seconds.
    201201 */
    202 static time_t _secs_since_epoch(const struct tm *tm)
     202static time_t _secs_since_epoch(const struct posix_tm *tm)
    203203{
    204204        return _days_since_epoch(tm->tm_year, tm->tm_mon, tm->tm_mday) *
     
    229229 * @return 0 on success, -1 on overflow
    230230 */
    231 static int _normalize_time(struct tm *tm, time_t sec_add)
     231static int _normalize_time(struct posix_tm *tm, time_t sec_add)
    232232{
    233233        // TODO: DST correction
     
    324324 * @return Week-based year.
    325325 */
    326 static int _wbyear(const struct tm *tm)
     326static int _wbyear(const struct posix_tm *tm)
    327327{
    328328        int day = tm->tm_yday - _wbyear_offset(tm->tm_year);
     
    347347 * @return The week number (0 - 53).
    348348 */
    349 static int _sun_week_number(const struct tm *tm)
     349static int _sun_week_number(const struct posix_tm *tm)
    350350{
    351351        int first_day = (7 - _day_of_week(tm->tm_year, 0, 1)) % 7;
     
    363363 * @return The week number (1 - 53).
    364364 */
    365 static int _iso_week_number(const struct tm *tm)
     365static int _iso_week_number(const struct posix_tm *tm)
    366366{
    367367        int day = tm->tm_yday - _wbyear_offset(tm->tm_year);
     
    386386 * @return The week number (0 - 53).
    387387 */
    388 static int _mon_week_number(const struct tm *tm)
     388static int _mon_week_number(const struct posix_tm *tm)
    389389{
    390390        int first_day = (1 - _day_of_week(tm->tm_year, 0, 1)) % 7;
     
    430430 * @return time_t representation of the time, undefined value on overflow.
    431431 */
    432 time_t posix_mktime(struct tm *tm)
     432time_t posix_mktime(struct posix_tm *tm)
    433433{
    434434        // TODO: take DST flag into account
     
    445445 * @return Normalized broken-down time in UTC, NULL on overflow.
    446446 */
    447 struct tm *posix_gmtime(const time_t *timer)
     447struct posix_tm *posix_gmtime(const time_t *timer)
    448448{
    449449        assert(timer != NULL);
    450450
    451         static struct tm result;
     451        static struct posix_tm result;
    452452        return posix_gmtime_r(timer, &result);
    453453}
     
    460460 * @return Value of result on success, NULL on overflow.
    461461 */
    462 struct tm *posix_gmtime_r(const time_t *restrict timer,
    463     struct tm *restrict result)
     462struct posix_tm *posix_gmtime_r(const time_t *restrict timer,
     463    struct posix_tm *restrict result)
    464464{
    465465        assert(timer != NULL);
     
    488488 * @return Normalized broken-down time in local timezone, NULL on overflow.
    489489 */
    490 struct tm *posix_localtime(const time_t *timer)
    491 {
    492         static struct tm result;
     490struct posix_tm *posix_localtime(const time_t *timer)
     491{
     492        static struct posix_tm result;
    493493        return posix_localtime_r(timer, &result);
    494494}
     
    501501 * @return Value of result on success, NULL on overflow.
    502502 */
    503 struct tm *posix_localtime_r(const time_t *restrict timer,
    504     struct tm *restrict result)
     503struct posix_tm *posix_localtime_r(const time_t *restrict timer,
     504    struct posix_tm *restrict result)
    505505{
    506506        // TODO: deal with timezone
     
    516516 * @return Pointer to a statically allocated string.
    517517 */
    518 char *posix_asctime(const struct tm *timeptr)
     518char *posix_asctime(const struct posix_tm *timeptr)
    519519{
    520520        static char buf[ASCTIME_BUF_LEN];
     
    531531 * @return Value of buf.
    532532 */
    533 char *posix_asctime_r(const struct tm *restrict timeptr,
     533char *posix_asctime_r(const struct posix_tm *restrict timeptr,
    534534    char *restrict buf)
    535535{
     
    563563char *posix_ctime(const time_t *timer)
    564564{
    565         struct tm *loctime = posix_localtime(timer);
     565        struct posix_tm *loctime = posix_localtime(timer);
    566566        if (loctime == NULL) {
    567567                return NULL;
     
    580580char *posix_ctime_r(const time_t *timer, char *buf)
    581581{
    582         struct tm loctime;
     582        struct posix_tm loctime;
    583583        if (posix_localtime_r(timer, &loctime) == NULL) {
    584584                return NULL;
     
    598598 */
    599599size_t posix_strftime(char *restrict s, size_t maxsize,
    600     const char *restrict format, const struct tm *restrict tm)
     600    const char *restrict format, const struct posix_tm *restrict tm)
    601601{
    602602        assert(s != NULL);
  • uspace/lib/posix/time.h

    r4cade47 r86e81a9  
    6969#define CLOCK_REALTIME ((posix_clockid_t) 0)
    7070
     71struct posix_tm {
     72        int tm_sec;         /* Seconds [0,60]. */
     73        int tm_min;         /* Minutes [0,59]. */
     74        int tm_hour;        /* Hour [0,23]. */
     75        int tm_mday;        /* Day of month [1,31]. */
     76        int tm_mon;         /* Month of year [0,11]. */
     77        int tm_year;        /* Years since 1900. */
     78        int tm_wday;        /* Day of week [0,6] (Sunday = 0). */
     79        int tm_yday;        /* Day of year [0,365]. */
     80        int tm_isdst;       /* Daylight Savings flag. */
     81};
     82
    7183struct posix_timespec {
    7284        time_t tv_sec; /* Seconds. */
     
    91103
    92104/* Broken-down Time */
    93 extern time_t posix_mktime(struct tm *tm);
    94 extern struct tm *posix_gmtime(const time_t *timer);
    95 extern struct tm *posix_gmtime_r(const time_t *restrict timer,
    96     struct tm *restrict result);
    97 extern struct tm *posix_localtime(const time_t *timer);
    98 extern struct tm *posix_localtime_r(const time_t *restrict timer,
    99     struct tm *restrict result);
     105extern time_t posix_mktime(struct posix_tm *tm);
     106extern struct posix_tm *posix_gmtime(const time_t *timer);
     107extern struct posix_tm *posix_gmtime_r(const time_t *restrict timer,
     108    struct posix_tm *restrict result);
     109extern struct posix_tm *posix_localtime(const time_t *timer);
     110extern struct posix_tm *posix_localtime_r(const time_t *restrict timer,
     111    struct posix_tm *restrict result);
    100112
    101113/* Formatting Calendar Time */
    102 extern char *posix_asctime(const struct tm *timeptr);
    103 extern char *posix_asctime_r(const struct tm *restrict timeptr,
     114extern char *posix_asctime(const struct posix_tm *timeptr);
     115extern char *posix_asctime_r(const struct posix_tm *restrict timeptr,
    104116    char *restrict buf);
    105117extern char *posix_ctime(const time_t *timer);
    106118extern char *posix_ctime_r(const time_t *timer, char *buf);
    107119extern size_t posix_strftime(char *restrict s, size_t maxsize,
    108     const char *restrict format, const struct tm *restrict tm);
     120    const char *restrict format, const struct posix_tm *restrict tm);
    109121
    110122/* Clocks */
     
    122134
    123135#ifndef LIBPOSIX_INTERNAL
     136        #define tm posix_tm
    124137        #define timespec posix_timespec
    125138        #define itimerspec posix_itimerspec
Note: See TracChangeset for help on using the changeset viewer.