Fix test.

This commit is contained in:
Victor Zverovich 2014-05-06 10:38:23 -07:00
parent 6a5f27bed2
commit 6bd3880cf1

View File

@ -102,9 +102,19 @@ void File::close() {
fmt::ThrowSystemError(errno, "cannot close file");
}
#ifdef _WIN32
// On Windows the count argument to read and write is unsigned, so convert
// it from size_t preventing integer overflow.
inline unsigned ConvertRWCount(std::size_t count) {
return count <= UINT_MAX ? count : UINT_MAX;
}
#else
inline std::size_t ConvertRWCount(std::size_t count) { return count; }
#endif
std::streamsize File::read(void *buffer, std::size_t count) {
std::streamsize result = 0;
FMT_RETRY(result, ::FMT_POSIX(read(fd_, buffer, count)));
FMT_RETRY(result, ::FMT_POSIX(read(fd_, buffer, ConvertRWCount(count))));
if (result == -1)
fmt::ThrowSystemError(errno, "cannot read from file");
return result;