X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/75a90b93257ea81d42331c03b56bd6589c62e065..9f3713fc037ca363b514c8d8f7cbb65fdab2e8b1:/apt-pkg/contrib/hashsum.cc diff --git a/apt-pkg/contrib/hashsum.cc b/apt-pkg/contrib/hashsum.cc index 0edcbb364..289e43aa4 100644 --- a/apt-pkg/contrib/hashsum.cc +++ b/apt-pkg/contrib/hashsum.cc @@ -14,7 +14,7 @@ bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) { while (Size != 0 || ToEOF) { unsigned long long n = sizeof(Buf); - if (!ToEOF) n = min(Size, n); + if (!ToEOF) n = std::min(Size, n); Res = read(Fd, Buf, n); if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read return false; @@ -24,5 +24,27 @@ bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) { Add(Buf,Res); } 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; } /*}}}*/