jiixyj / epoll-shim

small epoll implementation using kqueue; includes all features needed for libinput/libevdev
MIT License
88 stars 24 forks source link

timerfd.h only includes a forward declaration of struct itimerspec #44

Open jeremyhu opened 1 year ago

jeremyhu commented 1 year ago

Please define the struct in the header. Failure to do so results in build failures in clients such as Wayland:

../src/event-loop.c:261:20: error: variable has incomplete type 'struct itimerspec'
        struct itimerspec its;
                          ^
/opt/X11/include/libepoll-shim/sys/timerfd.h:17:8: note: forward declaration of 'struct itimerspec'
struct itimerspec;
       ^
../src/event-loop.c:272:20: error: variable has incomplete type 'struct itimerspec'
        struct itimerspec its;
                          ^
/opt/X11/include/libepoll-shim/sys/timerfd.h:17:8: note: forward declaration of 'struct itimerspec'
struct itimerspec;
       ^
2 errors generated.
jeremyhu commented 1 year ago

Wayland does:

static int
set_timer(int timerfd, struct timespec deadline) {
        struct itimerspec its;

        its.it_interval.tv_sec = 0;
        its.it_interval.tv_nsec = 0;
        its.it_value = deadline;
        return timerfd_settime(timerfd, TFD_TIMER_ABSTIME, &its, NULL);
}

static int
clear_timer(int timerfd)
{
        struct itimerspec its;

        its.it_interval.tv_sec = 0;
        its.it_interval.tv_nsec = 0;
        its.it_value.tv_sec = 0;
        its.it_value.tv_nsec = 0;
        return timerfd_settime(timerfd, 0, &its, NULL);
}
jiixyj commented 1 year ago

Thanks for the report! I had hoped to avoid defining that struct since it's either:

But that would of course mean that every program using epoll-shim on an OS that doesn't provide itimerspec would have to shim that struct itself, which leads to much duplication.

On which OS did that build error happen? macOS?

A solution could be for epoll-shim to provide a <time.h> shim header on OS's that need it.

jeremyhu commented 1 year ago

Yep, this is happening on macOS.

jeremyhu commented 1 year ago

Note that macOS is POSIX compliant. It's one of the few OSs that actually is certified POSIX compliant.

struct itimerspec is part of a the RT POSIX extension and is not required for POSIX compliance.

jiixyj commented 1 year ago

struct itimerspec is required for POSIX.1-2008 compliance: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html

macOS seems to be stuck on POSIX.1-2001, which is a shame, really...