From 7382127f0c08b3e6b269ae4ee33eafe70f0993af Mon Sep 17 00:00:00 2001 From: Rhys-T <108157737+Rhys-T@users.noreply.github.com> Date: Sun, 21 Jun 2026 16:13:40 -0400 Subject: [PATCH] Check for fdatasync, and fall back to fsync if missing Not all systems define fdatasync, and fsync does a strict superset of what fdatasync does. macOS has an fdatasync function in its standard library, but doesn't declare or document it. Apple Clang hides the warning/error when you try to call it without a declaration, but other compilers (including upstream Clang) don't. This is currently causing the Nix package for fcron to fail to build on macOS. --- config.h.in | 6 ++++++ configure.in | 2 ++ global.h | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/config.h.in b/config.h.in index 2ae5644..60b2d22 100644 --- a/config.h.in +++ b/config.h.in @@ -240,6 +240,12 @@ /* Define if you have the flock function. */ #undef HAVE_FLOCK +/* Define if you have the fdatasync function. */ +#undef HAVE_FDATASYNC + +/* Define if the headers actually declare the fdatasync function. */ +#undef HAVE_DECL_FDATASYNC + /* Define if you have the lockf function. */ #undef HAVE_LOCKF diff --git a/configure.in b/configure.in index 8e57f96..0b611e3 100644 --- a/configure.in +++ b/configure.in @@ -106,6 +106,8 @@ fi AC_CHECK_FUNCS(getcwd gettimeofday mktime putenv strerror setenv unsetenv gethostname) AC_CHECK_FUNCS(getopt_long) AC_CHECK_FUNCS(mkstemp) +AC_CHECK_FUNCS(fdatasync) +AC_CHECK_DECLS(fdatasync) AC_CHECK_FUNCS(flock lockf) AC_CHECK_FUNCS(setlinebuf) AC_CHECK_FUNCS(sigaction) diff --git a/global.h b/global.h index 12094ed..2d502f7 100644 --- a/global.h +++ b/global.h @@ -168,6 +168,14 @@ #endif /* macros */ +/* macOS has an fdatasync to link against, but doesn't declare or document it. + * Apple Clang suppresses the warning/error when calling it, which causes + * HAVE_FDATASYNC to be defined. But other compilers (including upstream Clang) + * don't. So we have to check both to see if we can safely use it. */ +#if !defined(HAVE_FDATASYNC) || !HAVE_DECL_FDATASYNC +#define fdatasync(arg) fsync(arg) +#endif + #ifndef HAVE_SETEUID #define seteuid(arg) setresuid(-1,(arg),-1) #endif