From 19fed0cab69dcb6ec6a5286e99c73116e3de0dc3 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Mon, 27 Jul 2026 12:56:21 +0000 Subject: [PATCH] timerfd.h: expose struct itimerspec to consumers on Apple compat_itimerspec.c/.h already provide struct itimerspec internally when the host libc is missing it (gated by add_compat_target(itimerspec "APPLE") in src/CMakeLists.txt), but the public include/sys/timerfd.h only ever forward-declares the struct, so any consumer including (e.g. foot) sees an incomplete type. Expose the same definition publicly behind COMPAT_ENABLE_ITIMERSPEC, and define that macro via pkg-config Cflags under the same condition the internal compat is compiled in, so consumers get it automatically without needing to know epoll-shim's internal macro names. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01U6fuL1PtRJHhr97gAGyS1h --- epoll-shim.pc.cmakein | 2 +- include/sys/timerfd.h | 14 ++++++++++++++ src/CMakeLists.txt | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/epoll-shim.pc.cmakein b/epoll-shim.pc.cmakein index 8703e48..c760379 100644 --- a/epoll-shim.pc.cmakein +++ b/epoll-shim.pc.cmakein @@ -9,4 +9,4 @@ Description: Small epoll implementation using kqueue Version: Libs: -L${libdir} -lepoll-shim Libs.private: -pthread -lrt -Cflags: -I${includedir}/libepoll-shim +Cflags: -I${includedir}/libepoll-shim @EPOLL_SHIM_EXTRA_PC_CFLAGS@ diff --git a/include/sys/timerfd.h b/include/sys/timerfd.h index 504c4bc..f5b6d42 100644 --- a/include/sys/timerfd.h +++ b/include/sys/timerfd.h @@ -14,7 +14,21 @@ extern "C" { #define TFD_TIMER_ABSTIME 1 #define TFD_TIMER_CANCEL_ON_SET (1 << 1) +#ifdef COMPAT_ENABLE_ITIMERSPEC +/* + * The host libc's doesn't define struct itimerspec (e.g. + * Darwin, which has no POSIX per-process timer support), so provide + * it here. Only defined when the build has actually detected the + * struct is missing (see CMakeLists.txt's HAVE_TIMERFD/APPLE check), + * to avoid ever conflicting with a real system definition. + */ +struct itimerspec { + struct timespec it_interval; + struct timespec it_value; +}; +#else struct itimerspec; +#endif int timerfd_create(int, int); int timerfd_settime(int, int, struct itimerspec const *, struct itimerspec *); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e64a3a1..bd3000e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -121,6 +121,19 @@ if(HAVE_TIMERFD) target_compile_definitions(epoll-shim PRIVATE HAVE_TIMERFD) endif() target_compile_definitions(epoll-shim PRIVATE EPOLL_SHIM_DISABLE_WRAPPER_MACROS) + +# struct itimerspec is missing from the host libc's under the +# same condition compat_itimerspec.c/.h are compiled in (see +# add_compat_target(itimerspec "APPLE") above). Consumers including +# need COMPAT_ENABLE_ITIMERSPEC defined too, via +# pkg-config Cflags, or they only see a forward declaration. +set(EPOLL_SHIM_EXTRA_PC_CFLAGS "") +if(NOT HAVE_TIMERFD AND APPLE) + set(EPOLL_SHIM_EXTRA_PC_CFLAGS "-DCOMPAT_ENABLE_ITIMERSPEC") +endif() +set(EPOLL_SHIM_EXTRA_PC_CFLAGS + "${EPOLL_SHIM_EXTRA_PC_CFLAGS}" + PARENT_SCOPE) target_include_directories( epoll-shim PRIVATE $