mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-10-30 07:30:46 +00:00
842093bb84
Stop trying to maintain a per-file _POSIX_C_SOURCE. Instead, require POSIX.1-2008 globally. A lot of core source files depend on that already. Some care must be taken on a few select files where we need a bit more than POSIX. Some files need XSI extensions (_XOPEN_SOURCE) and some files need BSD extensions (_DEFAULT_SOURCE). In both cases, these feature test macros imply _POSIX_C_SOURCE. Make sure to not define both these macros and _POSIX_C_SOURCE explicitly to avoid POSIX requirement conflicts (e.g. _POSIX_C_SOURCE says POSIX.1-2001 but _XOPEN_SOURCE says POSIX.1-2008). Additionally, there is one special case in render/vulkan/vulkan.c. That file needs major()/minor(), and these are system-specific. On FreeBSD, _POSIX_C_SOURCE hides system-specific symbols so we need to make sure it's not defined for this file. On Linux, we can explicitly include <sys/sysmacros.h> and ensure that apart from symbols defined there the file only uses POSIX toys.
36 lines
843 B
C
36 lines
843 B
C
#include <stdint.h>
|
|
#include <time.h>
|
|
|
|
#include "util/time.h"
|
|
|
|
static const long NSEC_PER_SEC = 1000000000;
|
|
|
|
int64_t timespec_to_msec(const struct timespec *a) {
|
|
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
|
|
}
|
|
|
|
int64_t timespec_to_nsec(const struct timespec *a) {
|
|
return (int64_t)a->tv_sec * NSEC_PER_SEC + a->tv_nsec;
|
|
}
|
|
|
|
void timespec_from_nsec(struct timespec *r, int64_t nsec) {
|
|
r->tv_sec = nsec / NSEC_PER_SEC;
|
|
r->tv_nsec = nsec % NSEC_PER_SEC;
|
|
}
|
|
|
|
int64_t get_current_time_msec(void) {
|
|
struct timespec now;
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
return timespec_to_msec(&now);
|
|
}
|
|
|
|
void timespec_sub(struct timespec *r, const struct timespec *a,
|
|
const struct timespec *b) {
|
|
r->tv_sec = a->tv_sec - b->tv_sec;
|
|
r->tv_nsec = a->tv_nsec - b->tv_nsec;
|
|
if (r->tv_nsec < 0) {
|
|
r->tv_sec--;
|
|
r->tv_nsec += NSEC_PER_SEC;
|
|
}
|
|
}
|