mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-01 21:33:09 +02: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
|
* @fd: a file descriptor
|
||||||
*
|
*
|
||||||
* A wrapper for the POSIX `fsync()` function. On Windows, `_commit()` will be
|
* 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
|
* The `fsync()` function is used to synchronize a file's in-core
|
||||||
* state with that of the disk.
|
* state with that of the disk.
|
||||||
*
|
*
|
||||||
@ -1679,10 +1679,14 @@ g_fsync (gint fd)
|
|||||||
{
|
{
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
return _commit (fd);
|
return _commit (fd);
|
||||||
#elif defined(HAVE_FSYNC)
|
#elif defined(HAVE_FSYNC) || defined(HAVE_FCNTL_F_FULLFSYNC)
|
||||||
int retval;
|
int retval;
|
||||||
do
|
do
|
||||||
|
#ifdef HAVE_FCNTL_F_FULLFSYNC
|
||||||
|
retval = fcntl (fd, F_FULLFSYNC, 0);
|
||||||
|
#else
|
||||||
retval = fsync (fd);
|
retval = fsync (fd);
|
||||||
|
#endif
|
||||||
while (G_UNLIKELY (retval < 0 && errno == EINTR));
|
while (G_UNLIKELY (retval < 0 && errno == EINTR));
|
||||||
return retval;
|
return retval;
|
||||||
#else
|
#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)
|
glib_conf.set('HAVE_OPEN_O_DIRECTORY', 1)
|
||||||
endif
|
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.
|
# Check whether there is a vsnprintf() function with C99 semantics installed.
|
||||||
# (similar tests to AC_FUNC_VSNPRINTF_C99)
|
# (similar tests to AC_FUNC_VSNPRINTF_C99)
|
||||||
# Check whether there is a snprintf() function with C99 semantics installed.
|
# Check whether there is a snprintf() function with C99 semantics installed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user