Commit cd02eac2 authored by Philip Withnall's avatar Philip Withnall

gstdio: Add macOS support to g_fsync()

Apparently, `fsync()` doesn’t actually sync to the spinning disk on
macOS. You need an `fcntl()` for that.

See: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html

Spotted by Christoph Reiter in a comment on !369.
Signed-off-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>
parent 926dfe59
......@@ -1661,7 +1661,7 @@ g_freopen (const gchar *filename,
* @fd: a file descriptor
*
* A wrapper for the POSIX `fsync()` function. On Windows, `_commit()` will be
* used.
* used. On macOS, `fcntl(F_FULLFSYNC)` will be used.
* The `fsync()` function is used to synchronize a file's in-core
* state with that of the disk.
*
......@@ -1679,10 +1679,14 @@ g_fsync (gint fd)
{
#ifdef G_OS_WIN32
return _commit (fd);
#elif defined(HAVE_FSYNC)
#elif defined(HAVE_FSYNC) || defined(HAVE_FCNTL_F_FULLFSYNC)
int retval;
do
#ifdef HAVE_FCNTL_F_FULLFSYNC
retval = fcntl (fd, F_FULLFSYNC, 0);
#else
retval = fsync (fd);
#endif
while (G_UNLIKELY (retval < 0 && errno == EINTR));
return retval;
#else
......
......@@ -875,6 +875,17 @@ if cc.compiles('''#include <fcntl.h>
glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
endif
# fcntl takes F_FULLFSYNC as an option
# See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
if cc.compiles('''#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
void some_func (void) {
fcntl(0, F_FULLFSYNC, 0);
}''', name : 'fcntl() option F_FULLFSYNC')
glib_conf.set('HAVE_FCNTL_F_FULLFSYNC', 1)
endif
# Check whether there is a vsnprintf() function with C99 semantics installed.
# (similar tests to AC_FUNC_VSNPRINTF_C99)
# Check whether there is a snprintf() function with C99 semantics installed.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment