Skip to content

Commit

Permalink
sendfile_posix: only use *64 APIs when _LARGEFILE64_SOURCE is defined
Browse files Browse the repository at this point in the history
*64 APIS are considered deprecated and should not be used
unless _LARGEFILE64_SOURCE is explicitly defined.
  • Loading branch information
aberaud committed Mar 17, 2024
1 parent 7994a15 commit 7e125f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion dev/restinio/impl/sendfile_operation_posix.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class sendfile_operation_runner_t final
virtual void
start() override
{
#if defined( RESTINIO_FREEBSD_TARGET ) || defined( RESTINIO_MACOS_TARGET )
#if !defined( _LARGEFILE64_SOURCE )
auto const n = ::lseek( this->m_file_descriptor, this->m_next_write_offset, SEEK_SET );
#else
auto const n = ::lseek64( this->m_file_descriptor, this->m_next_write_offset, SEEK_SET );
Expand Down Expand Up @@ -274,11 +274,19 @@ class sendfile_operation_runner_t< asio_ns::ip::tcp::socket > final
auto
call_native_sendfile() noexcept
{
#if defined( _LARGEFILE64_SOURCE )
return ::sendfile64(
m_socket.native_handle(),
m_file_descriptor,
&m_next_write_offset,
std::min< file_size_t >( m_remained_size, m_chunk_size ) );
#else
return ::sendfile(
m_socket.native_handle(),
m_file_descriptor,
&m_next_write_offset,
std::min< file_size_t >( m_remained_size, m_chunk_size ) );
#endif
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion dev/restinio/sendfile_defs_posix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ get_file_meta( file_descriptor_t fd )
throw exception_t{ "invalid file descriptor" };
}

#if defined( RESTINIO_FREEBSD_TARGET ) || defined( RESTINIO_MACOS_TARGET )
#if !defined( _LARGEFILE64_SOURCE )
struct stat file_stat;

const auto fstat_rc = ::fstat( fd, &file_stat );
Expand Down

0 comments on commit 7e125f8

Please sign in to comment.