diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2011-12-17 23:53:31 +0100 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2011-12-17 23:53:31 +0100 |
commit | 109eb1511d0cdfa4af3196105cada30bcbb77bc8 (patch) | |
tree | c07319a3ddc9a6484561d1cea918aaecade4a7e9 /apt-pkg/contrib/hashsum.cc | |
parent | 1abbc47c045770476f5f9a57c58989d13290d51b (diff) |
try to avoid direct usage of .Fd() if possible and do read()s and co
on the FileFd instead
Diffstat (limited to 'apt-pkg/contrib/hashsum.cc')
-rw-r--r-- | apt-pkg/contrib/hashsum.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/apt-pkg/contrib/hashsum.cc b/apt-pkg/contrib/hashsum.cc index ff3b112bb..289e43aa4 100644 --- a/apt-pkg/contrib/hashsum.cc +++ b/apt-pkg/contrib/hashsum.cc @@ -25,4 +25,26 @@ bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) { } return true; } +bool SummationImplementation::AddFD(FileFd &Fd, unsigned long long Size) { + unsigned char Buf[64 * 64]; + bool ToEOF = (Size == 0); + while (Size != 0 || ToEOF) + { + unsigned long long n = sizeof(Buf); + if (!ToEOF) n = std::min(Size, n); + unsigned long long a = 0; + if (Fd.Read(Buf, n, &a) == false) // error + return false; + if (ToEOF == false) + { + if (a != n) // short read + return false; + } + else if (a == 0) // EOF + break; + Size -= a; + Add(Buf, a); + } + return true; +} /*}}}*/ |