]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/hashsum.cc
releasing version 0.8.16~exp3
[apt.git] / apt-pkg / contrib / hashsum.cc
CommitLineData
c31c1dde
DK
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/* */
9bool SummationImplementation::AddFD(int const Fd, unsigned long Size) {
10 unsigned char Buf[64 * 64];
11 int Res = 0;
12 int ToEOF = (Size == 0);
c31c1dde
DK
13 while (Size != 0 || ToEOF)
14 {
1dab797c
DK
15 unsigned n = sizeof(Buf);
16 if (!ToEOF) n = min(Size,(unsigned long)n);
c31c1dde
DK
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 /*}}}*/