@@ -68,10 +68,11 @@ #import "OFLinkFailedException.h" #import "OFLockFailedException.h" #import "OFMoveItemFailedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" +#import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFRemoveItemFailedException.h" #import "OFSeekFailedException.h" #import "OFUnlockFailedException.h" #import "OFWriteFailedException.h" @@ -870,14 +871,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; @@ -884,13 +895,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 } - (off_t)lowlevelSeekToOffset: (off_t)offset whence: (int)whence {