]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/hashsum.cc
merge with my debian-sid branch
[apt.git] / apt-pkg / contrib / hashsum.cc
1 // Cryptographic API Base
2 #include <config.h>
3
4 #include <unistd.h>
5 #include "hashsum_template.h"
6
7 // Summation::AddFD - Add content of file into the checksum /*{{{*/
8 // ---------------------------------------------------------------------
9 /* */
10 bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
11 unsigned char Buf[64 * 64];
12 ssize_t Res = 0;
13 int ToEOF = (Size == 0);
14 while (Size != 0 || ToEOF)
15 {
16 unsigned long long n = sizeof(Buf);
17 if (!ToEOF) n = std::min(Size, n);
18 Res = read(Fd, Buf, n);
19 if (Res < 0 || (!ToEOF && Res != (ssize_t) 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 /*}}}*/