mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-26 14:13:18 -05:00
[misc] Add function to add a relative time to current clock
This commit is contained in:
parent
9aede45a12
commit
6db4e40119
16
src/misc.c
16
src/misc.c
@ -27,6 +27,7 @@
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
@ -928,6 +929,21 @@ timespec_cmp(struct timespec time1, struct timespec time2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct timespec
|
||||
timespec_reltoabs(struct timespec relative)
|
||||
{
|
||||
struct timespec absolute;
|
||||
|
||||
#if _POSIX_TIMERS > 0
|
||||
clock_gettime(CLOCK_REALTIME, &absolute);
|
||||
#else
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
TIMEVAL_TO_TIMESPEC(&tv, &absolute);
|
||||
#endif
|
||||
return timespec_add(absolute, relative);
|
||||
}
|
||||
|
||||
#if defined(HAVE_MACH_CLOCK) || defined(HAVE_MACH_TIMER)
|
||||
|
||||
#include <mach/mach_time.h> /* mach_absolute_time */
|
||||
|
@ -145,6 +145,9 @@ timespec_add(struct timespec time1, struct timespec time2);
|
||||
int
|
||||
timespec_cmp(struct timespec time1, struct timespec time2);
|
||||
|
||||
struct timespec
|
||||
timespec_reltoabs(struct timespec relative);
|
||||
|
||||
/* initialize mutex with error checking (not default on all platforms) */
|
||||
int
|
||||
mutex_init(pthread_mutex_t *mutex);
|
||||
|
Loading…
x
Reference in New Issue
Block a user