Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

@Rhys-T Rhys-T Jun 21, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option here, if you trust macOS's undocumented fdatasync function (which is what's currently being used if you build with Apple's tools), would be:

#if !HAVE_DECL_FDATASYNC
#if defined(__APPLE__) && defined(HAVE_FDATASYNC)
int fdatasync(int);
#else
#define fdatasync(arg) fsync(arg)
#endif
#endif

#endif

#ifndef HAVE_SETEUID
#define seteuid(arg) setresuid(-1,(arg),-1)
#endif
Expand Down