From 9bd54d3e470f293eab504f7ac0f5efbbd3affc43 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sun, 21 Jun 2009 21:07:35 +0000 Subject: [PATCH] Changed posix write wrapper since a) write can be interrupted and b) write can write less than specified without error (Georg Sauthoff). --- src/platforms/posix/posixFile.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/platforms/posix/posixFile.cpp b/src/platforms/posix/posixFile.cpp index 79da3515..9b16d035 100644 --- a/src/platforms/posix/posixFile.cpp +++ b/src/platforms/posix/posixFile.cpp @@ -127,8 +127,29 @@ posixFileWriterOutputStream::~posixFileWriterOutputStream() void posixFileWriterOutputStream::write(const value_type* const data, const size_type count) { - if (::write(m_fd, data, count) == -1) - posixFileSystemFactory::reportError(m_path, errno); + const value_type* array = data; + size_t size = count; + + while (1) + { + ssize_t ret = ::write(m_fd, array, size); + + if (ret == -1) + { + if (errno == EINTR) + continue; + + posixFileSystemFactory::reportError(m_path, errno); + break; + } + else if (size_t(ret) < size) + { + array += ret; + size -= ret; + } + + break; + } }