gstdio: Handle EINTR in g_fsync()

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2020-05-27 18:53:32 +01:00
parent 84dd89242a
commit 926dfe5925

View File

@ -1660,10 +1660,13 @@ g_freopen (const gchar *filename,
* g_fsync:
* @fd: a file descriptor
*
* A wrapper for the POSIX fsync() function (_commit() on Windows).
* The fsync() function is used to synchronize a file's in-core
* A wrapper for the POSIX `fsync()` function. On Windows, `_commit()` will be
* used.
* The `fsync()` function is used to synchronize a file's in-core
* state with that of the disk.
*
* This wrapper will handle retrying on `EINTR`.
*
* See the C library manual for more details about fsync().
*
* Returns: 0 on success, or -1 if an error occurred.
@ -1676,8 +1679,14 @@ g_fsync (gint fd)
{
#ifdef G_OS_WIN32
return _commit (fd);
#elif defined(HAVE_FSYNC)
int retval;
do
retval = fsync (fd);
while (G_UNLIKELY (retval < 0 && errno == EINTR));
return retval;
#else
return fsync (fd);
return 0;
#endif
}