Skip to content

Check for fdatasync, and fall back to fsync if missing#55

Open
Rhys-T wants to merge 1 commit into
yo8192:masterfrom
Rhys-T:test-for-fdatasync
Open

Check for fdatasync, and fall back to fsync if missing#55
Rhys-T wants to merge 1 commit into
yo8192:masterfrom
Rhys-T:test-for-fdatasync

Conversation

@Rhys-T

@Rhys-T Rhys-T commented Jun 21, 2026

Copy link
Copy Markdown

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.

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.
Comment thread global.h
* 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant