Possible workaround for OS X oddity with fdatasync() - GH#73.

This commit is contained in:
Andrew Wood
2023-08-06 20:45:46 +01:00
parent c2e77cd005
commit ada5748d2f
2 changed files with 9 additions and 1 deletions
+1
View File
@@ -3,6 +3,7 @@
* cleanup: added a test for terminal width detection to "`make test`"
* cleanup: added a test to "`make test`" to ensure that "`make install`" installs everything expected
* cleanup: replaced *AC_HEADER_TIOCGWINSZ* with *AC_CHECK_HEADERS(sys/ioctl.h)* for better MacOS compatibility ([GH#74](https://github.com/a-j-wood/pv/issues/74))
* cleanup: with "`--sync`", call `fsync()` instead of `fdatasync()` on incapable systems ([GH#73](https://github.com/a-j-wood/pv/issues/73))
1.7.24 - 30 July 2023
+8 -1
View File
@@ -96,7 +96,8 @@ static ssize_t pv__transfer_read_repeated(int fd, void *buf, size_t count)
* see if we can write any more, and keep trying, to make sure we empty the
* buffer as much as we can.
*
* If "sync_after_write" is true, we call fdatasync() after each write().
* If "sync_after_write" is true, we call fdatasync() after each write() (or
* fsync() if _POSIX_SYNCHRONIZED_IO is not > 0).
*
* We stop retrying if the time elapsed since this function was entered
* reaches TRANSFER_WRITE_TIMEOUT microseconds.
@@ -127,9 +128,15 @@ static ssize_t pv__transfer_write_repeated(int fd, void *buf, size_t count, bool
* descriptor), EINVAL (non syncable fd, such as a
* pipe), etc - only return an error on EIO.
*/
# if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
if ((fdatasync(fd) < 0) && (EIO == errno)) {
return -1;
}
# else
if ((fsync(fd) < 0) && (EIO == errno)) {
return -1;
}
# endif
}
#endif /* HAVE_FDATASYNC */