@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -12,10 +12,12 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" + +#include #import "OFTarArchive.h" #import "OFTarArchiveEntry.h" #import "OFTarArchiveEntry+Private.h" #import "OFDate.h" @@ -427,29 +429,32 @@ [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { - size_t bytesWritten; - if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if ((uint64_t)length > _toWrite) @throw [OFOutOfRangeException exception]; @try { - bytesWritten = [_stream writeBuffer: buffer - length: length]; + [_stream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { + OFEnsure(e.bytesWritten <= length); + _toWrite -= e.bytesWritten; + + if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) + return e.bytesWritten; + @throw e; } - _toWrite -= bytesWritten; + _toWrite -= length; - return bytesWritten; + return length; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil)