]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/md5.cc
test/test-indexes.sh: Stop hardcoding archive gpg key ID, get it from first failed...
[apt.git] / apt-pkg / contrib / md5.cc
index a095f8f0fbebf2ba71da0d0d3c0380c9d755e1d6..c0fa8493dff2e161099c57ad2ac7377a0006139f 100644 (file)
 // Include Files                                                       /*{{{*/
 #include <apt-pkg/md5.h>
 #include <apt-pkg/strutl.h>
+#include <apt-pkg/macros.h>
 
 #include <string.h>
 #include <unistd.h>
 #include <netinet/in.h>                          // For htonl
 #include <inttypes.h>
 #include <config.h>
-#include <system.h>
-
                                                                        /*}}}*/
 
 // byteSwap - Swap bytes in a buffer                                   /*{{{*/
@@ -294,11 +293,16 @@ bool MD5Summation::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;
       Add(Buf,Res);
    }