@@ -20,10 +20,11 @@ #import "OFStdIOStream.h" #import "OFDate.h" #import "OFApplication.h" +#import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #import "autorelease.h" #import "macros.h" @@ -92,14 +93,24 @@ - (size_t)lowlevelReadIntoBuffer: (void*)buffer length: (size_t)length { ssize_t ret; +#ifndef _WIN32 if (_fd == -1 || _atEndOfStream || (ret = read(_fd, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length]; +#else + if (length > UINT_MAX) + @throw [OFOutOfRangeException exception]; + + if (_fd == -1 || _atEndOfStream || + (ret = read(_fd, buffer, (unsigned int)length)) < 0) + @throw [OFReadFailedException exceptionWithObject: self + requestedLength: length]; +#endif if (ret == 0) _atEndOfStream = true; return ret; @@ -106,13 +117,23 @@ } - (void)lowlevelWriteBuffer: (const void*)buffer length: (size_t)length { +#ifndef _WIN32 if (_fd == -1 || _atEndOfStream || write(_fd, buffer, length) < length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; +#else + if (length > UINT_MAX) + @throw [OFOutOfRangeException exception]; + + if (_fd == -1 || _atEndOfStream || + write(_fd, buffer, (unsigned int)length) < length) + @throw [OFWriteFailedException exceptionWithObject: self + requestedLength: length]; +#endif } - (int)fileDescriptorForReading { return _fd;