Create header tile for timeutils, rename tval.c to time.c

This commit is contained in:
Nils O. Selåsdal
2013-12-25 19:42:40 +01:00
parent a147b868c0
commit 9756ca0aeb
2 changed files with 132 additions and 2 deletions
+86
View File
@@ -0,0 +1,86 @@
#ifndef UC_TIME_H_
#define UC_TIME_H_
#include <sys/time.h>
#include <stdint.h>
/** Add two struct timeval.
*
* @param dst where to store the result
* @param a first timeval to add
* @param b second timeval to add
* @return dst
*/
struct timeval *uc_tvadd(struct timeval *dst, const struct timeval *a, const struct timeval *b);
/** Subtract two struct timeval.
*
* @param dst where to store the result
* @param a first timeval to subtract
* @param b second timeval to subtract
* @return dst
*/
struct timeval *uc_tvsub(struct timeval *dst, const struct timeval *a, const struct timeval *b);
/** Add two struct timevals.
*
* @param dst where to store the result
* @param a first timeval to add
* @param b second timeval to add
* @return dst
*/
int uc_tvcmp(const struct timeval *a, const struct timeval *b);
/** Add two struct timespec.
*
* @param dst where to store the result
* @param a first timespec to add
* @param b second timespec to add
* @return dst
*/
struct timespec *uc_tsadd(struct timespec *dst, const struct timespec *a, const struct timespec *b);
/** Subtract two struct timespec.
*
* @param dst where to store the result
* @param a first timespec to subtract
* @param b second timespec to subtract
* @return dst
*/
struct timespec *uc_tssub(struct timespec *dst, const struct timespec *a, const struct timespec *b);
/** Add two struct timespec.
*
* @param a first timespec to add
* @param b second timespec to add
* @return < 0 if a is less than b, 0 if a and be are equal, > 0 if a is greater than b
*/
int uc_tscmp(const struct timespec *a, const struct timespec *b);
static inline uint64_t uc_tv2msec(const struct timeval *t)
{
return t->tv_sec * 1000 + t->tv_usec / 1000;
}
static inline uint64_t uc_ts2msec(const struct timespec *t)
{
return t->tv_sec * 1000 + t->tv_nsec / 10000000;
}
static inline uint64_t uc_ts2nsec(const struct timespec *t)
{
return t->tv_sec * 1000000000ULL + t->tv_nsec;
}
/** Convert number of miliseconds to a timeval.
*
* @param dst where to store the result
* @param ms number of miliseconds
* @return dst
*/
struct timeval *uc_ms2tv(struct timeval *dst, uint64_t ms);
#endif