@@ -20,10 +20,11 @@ #include /* include any libc header to get the libc defines */ #ifdef __GLIBC__ # undef __USE_XOPEN #endif +#include #include #import "OFStdIOStream.h" #import "OFDate.h" #import "OFApplication.h" @@ -96,23 +97,27 @@ - (size_t)lowlevelReadIntoBuffer: (void*)buffer length: (size_t)length { ssize_t ret; -#ifndef _WIN32 - if (_fd == -1 || _atEndOfStream || - (ret = read(_fd, buffer, length)) < 0) + if (_fd == -1 || _atEndOfStream) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length]; + +#ifndef _WIN32 + if ((ret = read(_fd, buffer, length)) < 0) + @throw [OFReadFailedException exceptionWithObject: self + requestedLength: length + errNo: errno]; #else if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; - if (_fd == -1 || _atEndOfStream || - (ret = read(_fd, buffer, (unsigned int)length)) < 0) + if ((ret = read(_fd, buffer, (unsigned int)length)) < 0) @throw [OFReadFailedException exceptionWithObject: self - requestedLength: length]; + requestedLength: length + errNo: errno]; #endif if (ret == 0) _atEndOfStream = true; @@ -120,22 +125,27 @@ } - (void)lowlevelWriteBuffer: (const void*)buffer length: (size_t)length { -#ifndef _WIN32 - if (_fd == -1 || _atEndOfStream || write(_fd, buffer, length) < length) + if (_fd == -1 || _atEndOfStream) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length]; + +#ifndef _WIN32 + if (write(_fd, buffer, length) < length) + @throw [OFWriteFailedException exceptionWithObject: self + requestedLength: length + errNo: errno]; #else if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; - if (_fd == -1 || _atEndOfStream || - write(_fd, buffer, (unsigned int)length) < length) + if (write(_fd, buffer, (unsigned int)length) < length) @throw [OFWriteFailedException exceptionWithObject: self - requestedLength: length]; + requestedLength: length + errNo: errno]; #endif } - (int)fileDescriptorForReading {