]> git.saurik.com Git - apt.git/blob - apt-pkg/contrib/hashsum.cc
728747d7ab00ed47b44cc36706ae88daf549d994
[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 while (Size != 0 || ToEOF)
14 {
15 unsigned n = sizeof(Buf);
16 if (!ToEOF) n = min(Size,(unsigned long)n);
17 Res = read(Fd, Buf, n);
18 if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
19 return false;
20 if (ToEOF && Res == 0) // EOF
21 break;
22 Size -= Res;
23 Add(Buf,Res);
24 }
25 return true;
26 }
27 /*}}}*/