Changeset daa90e8 in mainline for uspace/lib/libc/generic/time.c


Ignore:
Timestamp:
2007-07-02T18:30:54Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7b63b6b
Parents:
f2f0392
Message:

Remove duplicit and empty time.h from libc.
Move timeval functions from async.c to time.c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/time.c

    rf2f0392 rdaa90e8  
    5454        volatile sysarg_t seconds2;
    5555} *ktime = NULL;
     56
     57/** Add microseconds to given timeval.
     58 *
     59 * @param tv            Destination timeval.
     60 * @param usecs         Number of microseconds to add.
     61 */
     62void tv_add(struct timeval *tv, suseconds_t usecs)
     63{
     64        tv->tv_sec += usecs / 1000000;
     65        tv->tv_usec += usecs % 1000000;
     66        if (tv->tv_usec > 1000000) {
     67                tv->tv_sec++;
     68                tv->tv_usec -= 1000000;
     69        }
     70}
     71
     72/** Subtract two timevals.
     73 *
     74 * @param tv1           First timeval.
     75 * @param tv2           Second timeval.
     76 *
     77 * @return              Return difference between tv1 and tv2 (tv1 - tv2) in
     78 *                      microseconds.
     79 */
     80suseconds_t tv_sub(struct timeval *tv1, struct timeval *tv2)
     81{
     82        suseconds_t result;
     83
     84        result = tv1->tv_usec - tv2->tv_usec;
     85        result += (tv1->tv_sec - tv2->tv_sec) * 1000000;
     86
     87        return result;
     88}
     89
     90/** Decide if one timeval is greater than the other.
     91 *
     92 * @param t1            First timeval.
     93 * @param t2            Second timeval.
     94 *
     95 * @return              Return true tv1 is greater than tv2. Otherwise return
     96 *                      false.
     97 */
     98int tv_gt(struct timeval *tv1, struct timeval *tv2)
     99{
     100        if (tv1->tv_sec > tv2->tv_sec)
     101                return 1;
     102        if (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec > tv2->tv_usec)
     103                return 1;
     104        return 0;
     105}
     106
     107/** Decide if one timeval is greater than or equal to the other.
     108 *
     109 * @param tv1           First timeval.
     110 * @param tv2           Second timeval.
     111 *
     112 * @return              Return true if tv1 is greater than or equal to tv2.
     113 *                      Otherwise return false.
     114 */
     115int tv_gteq(struct timeval *tv1, struct timeval *tv2)
     116{
     117        if (tv1->tv_sec > tv2->tv_sec)
     118                return 1;
     119        if (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec >= tv2->tv_usec)
     120                return 1;
     121        return 0;
     122}
    56123
    57124
Note: See TracChangeset for help on using the changeset viewer.