reorder includes: add <config.h> if needed and include it at first
[ntk/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 Size) {
11 unsigned char Buf[64 * 64];
12 int Res = 0;
13 int ToEOF = (Size == 0);
14 while (Size != 0 || ToEOF)
15 {
16 unsigned n = sizeof(Buf);
17 if (!ToEOF) n = min(Size,(unsigned long)n);
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 /*}}}*/