mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
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 <withnall@endlessm.com>
This commit is contained in:
parent
926dfe5925
commit
cd02eac2d4
@ -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
|
||||
|
11
meson.build
11
meson.build
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user