Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/time.c

    ra12f7f1 r3f466c33  
    3131 * @{
    3232 */
    33 /** @file Time measurement support.
     33/** @file
    3434 */
    3535
     
    6363#define SECS_PER_DAY (SECS_PER_HOUR * HOURS_PER_DAY)
    6464
    65 /**
    66  *
    67  * @param year
    68  * @return
    69  */
    7065static bool _is_leap_year(time_t year)
    7166{
     
    8176}
    8277
    83 /**
    84  *
    85  * @param year
    86  * @param mon
    87  * @return
    88  */
    8978static int _days_in_month(time_t year, time_t mon)
    9079{
     
    10392}
    10493
    105 /**
    106  *
    107  * @param year
    108  * @param mon
    109  * @param mday
    110  * @return
    111  */
    11294static int _day_of_year(time_t year, time_t mon, time_t mday)
    11395{
     
    120102}
    121103
    122 /**
    123  * Integer division that rounds to negative infinity.
    124  *
    125  * @param op1
    126  * @param op2
    127  * @return
     104/* Integer division that rounds to negative infinity.
    128105 */
    129106static time_t _floor_div(time_t op1, time_t op2)
     
    136113}
    137114
    138 /**
    139  * Modulo that rounds to negative infinity.
    140  *
    141  * @param op1
    142  * @param op2
    143  * @return
     115/* Modulo that rounds to negative infinity.
    144116 */
    145117static time_t _floor_mod(time_t op1, time_t op2)
     
    160132}
    161133
    162 /**
    163  *
    164  * @param year
    165  * @param mon
    166  * @param mday
    167  * @return
    168  */
    169134static time_t _days_since_epoch(time_t year, time_t mon, time_t mday)
    170135{
     
    174139}
    175140
    176 /**
    177  * Assumes normalized broken-down time.
    178  *
    179  * @param tm
    180  * @return
    181  */
     141/* Assumes normalized broken-down time. */
    182142static time_t _secs_since_epoch(const struct posix_tm *tm)
    183143{
     
    187147}
    188148
    189 /**
    190  *
    191  * @param year
    192  * @param mon
    193  * @param mday
    194  * @return
    195  */
    196149static int _day_of_week(time_t year, time_t mon, time_t mday)
    197150{
     
    212165};
    213166
    214 /**
    215  *
    216  * @param ltm
    217  * @param ptm
    218  */
    219167static void _posix_to_long_tm(struct _long_tm *ltm, struct posix_tm *ptm)
    220168{
     
    231179}
    232180
    233 /**
    234  *
    235  * @param ptm
    236  * @param ltm
    237  */
    238181static void _long_to_posix_tm(struct posix_tm *ptm, struct _long_tm *ltm)
    239182{
     
    253196}
    254197
    255 /**
    256  *
    257  * @param tm
    258  */
    259198static void _normalize_time(struct _long_tm *tm)
    260199{
     
    302241}
    303242
    304 /**
    305  * Which day the week-based year starts on relative to the first calendar day.
     243/* Which day the week-based year starts on relative to the first calendar day.
    306244 * E.g. if the year starts on December 31st, the return value is -1.
    307  *
    308  * @param year
    309  * @return
    310245 */
    311246static int _wbyear_offset(int year)
     
    315250}
    316251
    317 /**
    318  * Returns week-based year of the specified time.
     252/* Returns week-based year of the specified time.
    319253 * Assumes normalized broken-down time.
    320  *
    321  * @param tm
    322  * @return
    323254 */
    324255static int _wbyear(const struct posix_tm *tm)
     
    337268}
    338269
    339 /**
    340  * Week number of the year, assuming weeks start on sunday.
    341  * The first Sunday of January is the first day of week 1;
    342  * days in the new year before this are in week 0.
     270/** Week number of the year, assuming weeks start on sunday.
     271 *  The first Sunday of January is the first day of week 1;
     272 *  days in the new year before this are in week 0.
    343273 *
    344274 * @param tm Normalized broken-down time.
     
    351281}
    352282
    353 /**
    354  * Week number of the year, assuming weeks start on monday.
    355  * If the week containing January 1st has four or more days in the new year,
    356  * then it is considered week 1. Otherwise, it is the last week of the previous
    357  * year, and the next week is week 1. Both January 4th and the first Thursday
    358  * of January are always in week 1.
     283/** Week number of the year, assuming weeks start on monday.
     284 *  If the week containing January 1st has four or more days in the new year,
     285 *  then it is considered week 1. Otherwise, it is the last week of the previous
     286 *  year, and the next week is week 1. Both January 4th and the first Thursday
     287 *  of January are always in week 1.
    359288 *
    360289 * @param tm Normalized broken-down time.
     
    376305}
    377306
    378 /**
    379  * Week number of the year, assuming weeks start on monday.
    380  * The first Monday of January is the first day of week 1;
    381  * days in the new year before this are in week 0.
     307/** Week number of the year, assuming weeks start on monday.
     308 *  The first Monday of January is the first day of week 1;
     309 *  days in the new year before this are in week 0.
    382310 *
    383311 * @param tm Normalized broken-down time.
     
    396324char *posix_tzname[2];
    397325
    398 /**
    399  *
    400  */
    401326void posix_tzset(void)
    402327{
     
    408333}
    409334
    410 /**
    411  *
    412  * @param time1
    413  * @param time0
    414  * @return
    415  */
    416335double posix_difftime(time_t time1, time_t time0)
    417336{
     
    419338}
    420339
    421 /**
    422  * This function first normalizes the provided broken-down time
    423  * (moves all values to their proper bounds) and then tries to
    424  * calculate the appropriate time_t representation.
    425  *
    426  * @param tm Broken-down time.
     340/** This function first normalizes the provided broken-down time
     341 *  (moves all values to their proper bounds) and then tries to
     342 *  calculate the appropriate time_t representation.
     343 *
     344 * @param timeptr Broken-down time.
    427345 * @return time_t representation of the time, undefined value on overflow
    428346 */
     
    440358}
    441359
    442 /**
    443  *
    444  * @param timer
    445  * @return
    446  */
    447360struct posix_tm *posix_gmtime(const time_t *timer)
    448361{
     
    451364}
    452365
    453 /**
    454  *
    455  * @param timer
    456  * @param result
    457  * @return
    458  */
    459366struct posix_tm *posix_gmtime_r(const time_t *restrict timer,
    460367    struct posix_tm *restrict result)
     
    487394/**
    488395 *
    489  * @param timer
     396 * @param timep
    490397 * @return
    491398 */
     
    496403}
    497404
    498 /**
    499  *
    500  * @param timer
    501  * @param result
    502  * @return
    503  */
    504405struct posix_tm *posix_localtime_r(const time_t *restrict timer,
    505406    struct posix_tm *restrict result)
     
    512413/**
    513414 *
    514  * @param timeptr
     415 * @param tm
    515416 * @return
    516417 */
     
    521422}
    522423
    523 /**
    524  *
    525  * @param timeptr
    526  * @param buf
    527  * @return
    528  */
    529424char *posix_asctime_r(const struct posix_tm *restrict timeptr,
    530425    char *restrict buf)
     
    553448/**
    554449 *
    555  * @param timer
     450 * @param timep
    556451 * @return
    557452 */
     
    565460}
    566461
    567 /**
    568  *
    569  * @param timer
    570  * @param buf
    571  * @return
    572  */
    573462char *posix_ctime_r(const time_t *timer, char *buf)
    574463{
     
    588477 * @return
    589478 */
    590 size_t posix_strftime(char *restrict s, size_t maxsize,
    591     const char *restrict format, const struct posix_tm *restrict tm)
     479size_t posix_strftime(char *s, size_t maxsize,
     480    const char *format, const struct posix_tm *tm)
    592481{
    593482        // TODO: use locale
     
    766655}
    767656
    768 /**
    769  *
    770  * @param s
    771  * @param maxsize
    772  * @param format
    773  * @param tm
    774  * @param loc
    775  * @return
    776  */
    777 extern size_t posix_strftime_l(char *restrict s, size_t maxsize,
    778     const char *restrict format, const struct posix_tm *restrict tm,
    779     posix_locale_t loc)
    780 {
    781         // TODO
    782         not_implemented();
    783 }
    784 
    785 /**
    786  *
    787  * @param clock_id
    788  * @param res
    789  * @return
    790  */
    791657int posix_clock_getres(posix_clockid_t clock_id, struct posix_timespec *res)
    792658{
     
    804670}
    805671
    806 /**
    807  *
    808  * @param clock_id
    809  * @param tp
    810  * @return
    811  */
    812672int posix_clock_gettime(posix_clockid_t clock_id, struct posix_timespec *tp)
    813673{
     
    828688}
    829689
    830 /**
    831  *
    832  * @param clock_id
    833  * @param tp
    834  * @return
    835  */
    836690int posix_clock_settime(posix_clockid_t clock_id,
    837691    const struct posix_timespec *tp)
     
    852706}
    853707
    854 /**
    855  *
    856  * @param clock_id
    857  * @param flags
    858  * @param rqtp
    859  * @param rmtp
    860  * @return
    861  */
    862708int posix_clock_nanosleep(posix_clockid_t clock_id, int flags,
    863709    const struct posix_timespec *rqtp, struct posix_timespec *rmtp)
     
    889735};
    890736
    891 /**
    892  *
    893  * @param clockid
    894  * @param evp
    895  * @param timerid
    896  * @return
    897  */
    898737int posix_timer_create(posix_clockid_t clockid,
    899738    struct posix_sigevent *restrict evp,
     
    904743}
    905744
    906 /**
    907  *
    908  * @param timerid
    909  * @return
    910  */
    911745int posix_timer_delete(posix_timer_t timerid)
    912746{
     
    915749}
    916750
    917 /**
    918  *
    919  * @param timerid
    920  * @return
    921  */
    922751int posix_timer_getoverrun(posix_timer_t timerid)
    923752{
     
    926755}
    927756
    928 /**
    929  *
    930  * @param timerid
    931  * @param value
    932  * @return
    933  */
    934757int posix_timer_gettime(posix_timer_t timerid,
    935758    struct posix_itimerspec *value)
     
    939762}
    940763
    941 /**
    942  *
    943  * @param timerid
    944  * @param flags
    945  * @param value
    946  * @param ovalue
    947  * @return
    948  */
    949764int posix_timer_settime(posix_timer_t timerid, int flags,
    950765    const struct posix_itimerspec *restrict value,
     
    968783        if (task_stats) {
    969784                total_cycles = (posix_clock_t) (task_stats->kcycles + task_stats->ucycles);
    970                 free(task_stats);
    971                 task_stats = 0;
    972         }
     785        }
     786        free(task_stats);
     787        task_stats = 0;
    973788
    974789        return total_cycles;
Note: See TracChangeset for help on using the changeset viewer.