diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2012-04-11 13:25:28 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2012-04-11 13:25:28 +0200 |
commit | d68d65ad637526e46ea77ab83e07470d26df15fc (patch) | |
tree | 0873a85635b7940842fa4d31898895f3618155b8 /apt-pkg/contrib/fileutl.cc | |
parent | 3b4d8136e78b9f2a70431ece4c850861d90e8bb1 (diff) |
use a static FileFd::Write overload to reduce duplication of write()-retry code
Diffstat (limited to 'apt-pkg/contrib/fileutl.cc')
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 536571fee..9e3611b26 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -1302,6 +1302,28 @@ bool FileFd::Write(const void *From,unsigned long long Size) Flags |= Fail; return _error->Error(_("write, still have %llu to write but couldn't"), Size); } +bool FileFd::Write(int Fd, const void *From, unsigned long long Size) +{ + int Res; + errno = 0; + do + { + Res = write(Fd,From,Size); + if (Res < 0 && errno == EINTR) + continue; + if (Res < 0) + return _error->Errno("write",_("Write error")); + + From = (char *)From + Res; + Size -= Res; + } + while (Res > 0 && Size > 0); + + if (Size == 0) + return true; + + return _error->Error(_("write, still have %llu to write but couldn't"), Size); +} /*}}}*/ // FileFd::Seek - Seek in the file /*{{{*/ // --------------------------------------------------------------------- |