Skip to content

Commit

Permalink
fix FreeBSD build, lacking fsync_range()
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Jul 21, 2024
1 parent 37192ae commit 796c953
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 8 additions & 0 deletions include/libtorrent/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ see LICENSE file.
|| defined __FreeBSD_kernel__
#define TORRENT_BSD

#ifdef __NetBSD__
#define TORRENT_HAS_FSYNC_RANGE 1
#endif

#if defined __APPLE__

#include <AvailabilityMacros.h>
Expand Down Expand Up @@ -560,6 +564,10 @@ see LICENSE file.
#define TORRENT_HAS_COPYFILE 0
#endif

#ifndef TORRENT_HAS_FSYNC_RANGE
#define TORRENT_HAS_FSYNC_RANGE 0
#endif

// debug builds have asserts enabled by default, release
// builds have asserts if they are explicitly enabled by
// the release_asserts macro.
Expand Down
10 changes: 3 additions & 7 deletions src/pread_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ see LICENSE file.
#include <fcntl.h> // for sync_file_range
#elif defined TORRENT_WINDOWS
#include "libtorrent/aux_/windows.hpp" // for FlushFileBuffers
#elif defined TORRENT_BSD && ! defined __APPLE__
#elif TORRENT_HAS_FSYNC_RANGE
#include <unistd.h> // for fsync_range
#else
#include <unistd.h> // for fsync
Expand Down Expand Up @@ -72,8 +72,8 @@ namespace {
::FlushFileBuffers(handle);
TORRENT_UNUSED(offset);
TORRENT_UNUSED(len);
#elif defined TORRENT_BSD && ! defined __APPLE__
::fsync_range(handle, FFILESYNC, offset, len);
#elif TORRENT_HAS_FSYNC_RANGE
::fsync_range(handle, FDATASYNC, offset, len);
#else
::fsync(handle);
TORRENT_UNUSED(offset);
Expand Down Expand Up @@ -634,8 +634,6 @@ namespace {
ph.update(scratch_buffer);
if (flags & disk_interface::volatile_read)
advise_dont_need(handle->fd(), file_offset, buf.size());
if (flags & disk_interface::flush_piece)
sync_file(handle->fd(), file_offset, buf.size());
}

return ret;
Expand Down Expand Up @@ -688,8 +686,6 @@ namespace {
ph.update(b);
if (flags & disk_interface::volatile_read)
advise_dont_need(handle->fd(), file_offset, len);
if (flags & disk_interface::flush_piece)
sync_file(handle->fd(), file_offset, len);

return static_cast<int>(len);
}
Expand Down

0 comments on commit 796c953

Please sign in to comment.