summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/hashes.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-07-16 12:59:39 +0200
committerJulian Andres Klode <jak@debian.org>2009-07-16 12:59:39 +0200
commit04f4e1a3b110ef5ff8870816169f8f0b9eb23dce (patch)
tree7dc27a5dae41ae1229e8bf14eaa5e16a28249b10 /apt-pkg/contrib/hashes.cc
parent6e7c6c3f58193fd5db3d9d598ac65a1571522a58 (diff)
* apt-pkg/contrib/hashes.cc, apt-pkg/contrib/md5.cc:
- Support reading until EOF if Size=0 to match behaviour of SHA1Summation and SHA256Summation
Diffstat (limited to 'apt-pkg/contrib/hashes.cc')
-rw-r--r--apt-pkg/contrib/hashes.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index fcc2f887c..70f2db06d 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -108,11 +108,16 @@ bool Hashes::AddFD(int Fd,unsigned long Size)
{
unsigned char Buf[64*64];
int Res = 0;
- while (Size != 0)
+ int ToEOF = (Size == 0);
+ while (Size != 0 || ToEOF)
{
- Res = read(Fd,Buf,min(Size,(unsigned long)sizeof(Buf)));
- if (Res < 0 || (unsigned)Res != min(Size,(unsigned long)sizeof(Buf)))
- return false;
+ unsigned n = sizeof(Buf);
+ if (!ToEOF) n = min(Size,(unsigned long)n);
+ Res = read(Fd,Buf,n);
+ if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
+ return false;
+ if (ToEOF && Res == 0) // EOF
+ break;
Size -= Res;
MD5.Add(Buf,Res);
SHA1.Add(Buf,Res);