]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/hashes.cc
* apt-pkg/contrib/cdromutl.cc:
[apt.git] / apt-pkg / contrib / hashes.cc
index 52b9bfbe6c78e18ce24d02119a56a610d93b21a2..985d89d903ea502c448d28aa2bb819c121d8eb64 100644 (file)
@@ -14,9 +14,9 @@
 #include <apt-pkg/hashes.h>
 #include <apt-pkg/fileutl.h>
 #include <apt-pkg/configuration.h>
-    
+#include <apt-pkg/macros.h>
+
 #include <unistd.h>    
-#include <system.h>    
 #include <string>
 #include <iostream>
                                                                        /*}}}*/
@@ -105,11 +105,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);