]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/hashsum.cc
b97eaf831195d84946e58c41e26ddf514e8ebae7
[apt.git] / apt-pkg / contrib / hashsum.cc
1 // Cryptographic API Base
2
3 #include <unistd.h>
4 #include "hashsum_template.h"
5
6 // Summation::AddFD - Add content of file into the checksum /*{{{*/
7 // ---------------------------------------------------------------------
8 /* */
9 bool SummationImplementation::AddFD(int const Fd, unsigned long Size) {
10 unsigned char Buf[64 * 64];
11 int Res = 0;
12 int ToEOF = (Size == 0);
13 unsigned long n = sizeof(Buf);
14 if (!ToEOF)
15 n = std::min(Size, n);
16 while (Size != 0 || ToEOF)
17 {
18 Res = read(Fd, Buf, n);
19 if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
20 return false;
21 if (ToEOF && Res == 0) // EOF
22 break;
23 Size -= Res;
24 Add(Buf,Res);
25 }
26 return true;
27 }
28 /*}}}*/