Check for fdatasync, and fall back to fsync if missing#55
Open
Rhys-T wants to merge 1 commit into
Open
Conversation
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.
Rhys-T
commented
Jun 21, 2026
| * 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) |
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Not all systems define
fdatasync, andfsyncdoes a strict superset of whatfdatasyncdoes.macOS has an
fdatasyncfunction 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 forfcronto fail to build on macOS.