std::min(count, bufferSize) fails to compile when bufferSize is a 32-bit unsigned value, at least with GCC 12, because the STL can't find a template for std::min that will compare std::uint64_t to unsigned int. This is fixed by forcing the comparison for 64-bit types, then casting back down to the std::size_t expected by sendfile64. The down-cast can never overflow because the argument is always guaranteed to be no larger than the maximum representable size of the std::size_t bufferSize argument, so this should always be safe.
std::min(count, bufferSize)
fails to compile whenbufferSize
is a 32-bit unsigned value, at least with GCC 12, because the STL can't find a template forstd::min
that will comparestd::uint64_t
tounsigned int
. This is fixed by forcing the comparison for 64-bit types, then casting back down to thestd::size_t
expected bysendfile64
. The down-cast can never overflow because the argument is always guaranteed to be no larger than the maximum representable size of thestd::size_t bufferSize
argument, so this should always be safe.