From 5546086ca9c7494449552784d8acf08e833ed2e7 Mon Sep 17 00:00:00 2001 From: Richard Hodges Date: Thu, 13 May 2021 21:06:40 +0200 Subject: [PATCH] Remove use of POSIX-only constant fixes #2233 refs #2231 --- CHANGELOG.md | 4 ++++ include/boost/beast/core/impl/file_posix.ipp | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac1d5791..f3c8bfff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +* Remove use of POSIX-only constant. + +-------------------------------------------------------------------------------- + Version 317: * Remove travis CI. diff --git a/include/boost/beast/core/impl/file_posix.ipp b/include/boost/beast/core/impl/file_posix.ipp index 61a33a52..1bb7ae10 100644 --- a/include/boost/beast/core/impl/file_posix.ipp +++ b/include/boost/beast/core/impl/file_posix.ipp @@ -270,8 +270,12 @@ read(void* buffer, std::size_t n, error_code& ec) const std::size_t nread = 0; while(n > 0) { - auto const amount = static_cast((std::min)( - n, static_cast(SSIZE_MAX))); + // not required to define SSIZE_MAX so we avoid it + constexpr auto ssmax = + static_cast((std::numeric_limits< + decltype(::read(fd_, buffer, n))>::max)()); + auto const amount = (std::min)( + n, ssmax); auto const result = ::read(fd_, buffer, amount); if(result == -1) { @@ -305,8 +309,12 @@ write(void const* buffer, std::size_t n, error_code& ec) std::size_t nwritten = 0; while(n > 0) { - auto const amount = static_cast((std::min)( - n, static_cast(SSIZE_MAX))); + // not required to define SSIZE_MAX so we avoid it + constexpr auto ssmax = + static_cast((std::numeric_limits< + decltype(::write(fd_, buffer, n))>::max)()); + auto const amount = (std::min)( + n, ssmax); auto const result = ::write(fd_, buffer, amount); if(result == -1) {