diff options
Diffstat (limited to 'src/xtime.h')
-rw-r--r-- | src/xtime.h | 97 |
1 files changed, 61 insertions, 36 deletions
diff --git a/src/xtime.h b/src/xtime.h index 75d1f4e..b76fef2 100644 --- a/src/xtime.h +++ b/src/xtime.h @@ -11,73 +11,98 @@ #include <time.h> /** - * localtime_r() wrapper that calls tzset() first. + * mktime() wrapper that reports errors more reliably. * - * @param[in] timep - * The time_t to convert. - * @param[out] result - * Buffer to hold the result. + * @tm[in,out] + * The struct tm to convert and normalize. + * @timep[out] + * A pointer to the result. * @return * 0 on success, -1 on failure. */ -int xlocaltime(const time_t *timep, struct tm *result); +int xmktime(struct tm *tm, time_t *timep); /** - * gmtime_r() wrapper that calls tzset() first. + * A portable timegm(), the inverse of gmtime(). * - * @param[in] timep - * The time_t to convert. - * @param[out] result - * Buffer to hold the result. + * @tm[in,out] + * The struct tm to convert and normalize. + * @timep[out] + * A pointer to the result. * @return * 0 on success, -1 on failure. */ -int xgmtime(const time_t *timep, struct tm *result); +int xtimegm(struct tm *tm, time_t *timep); /** - * mktime() wrapper that reports errors more reliably. + * Parse an ISO 8601-style timestamp. * - * @param[in,out] tm - * The struct tm to convert. - * @param[out] timep + * @str + * The string to parse. + * @result[out] * A pointer to the result. * @return * 0 on success, -1 on failure. */ -int xmktime(struct tm *tm, time_t *timep); +int xgetdate(const char *str, struct timespec *result); /** - * A portable timegm(), the inverse of gmtime(). + * Add to a timespec. + */ +void timespec_add(struct timespec *lhs, const struct timespec *rhs); + +/** + * Subtract from a timespec. + */ +void timespec_sub(struct timespec *lhs, const struct timespec *rhs); + +/** + * Compare two timespecs. * - * @param[in,out] tm - * The struct tm to convert. - * @param[out] timep - * A pointer to the result. * @return - * 0 on success, -1 on failure. + * An integer with the sign of (*lhs - *rhs). */ -int xtimegm(struct tm *tm, time_t *timep); +int timespec_cmp(const struct timespec *lhs, const struct timespec *rhs); /** - * Parse an ISO 8601-style timestamp. + * Update a minimum timespec. + */ +void timespec_min(struct timespec *dest, const struct timespec *src); + +/** + * Update a maximum timespec. + */ +void timespec_max(struct timespec *dest, const struct timespec *src); + +/** + * Convert a timespec to floating point. * - * @param[in] str - * The string to parse. - * @param[out] result - * A pointer to the result. * @return - * 0 on success, -1 on failure. + * The value in nanoseconds. */ -int xgetdate(const char *str, struct timespec *result); +double timespec_ns(const struct timespec *ts); /** - * Get the current time. + * A timer. + */ +struct timer; + +/** + * Start a timer. * - * @param[out] result - * A pointer to the result. + * @interval + * The regular interval at which to send SIGALRM. * @return - * 0 on success, -1 on failure. + * The new timer on success, otherwise NULL. + */ +struct timer *xtimer_start(const struct timespec *interval); + +/** + * Stop a timer. + * + * @timer + * The timer to stop. */ -int xgettime(struct timespec *result); +void xtimer_stop(struct timer *timer); #endif // BFS_XTIME_H |