]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/hashsum.cc
Prepare release 1.1~exp17
[apt.git] / apt-pkg / contrib / hashsum.cc
CommitLineData
c31c1dde 1// Cryptographic API Base
ea542140 2#include <config.h>
c31c1dde 3
453b82a3
DK
4#include <apt-pkg/fileutl.h>
5
6#include <algorithm>
c31c1dde
DK
7#include <unistd.h>
8#include "hashsum_template.h"
9
10// Summation::AddFD - Add content of file into the checksum /*{{{*/
11// ---------------------------------------------------------------------
12/* */
650faab0 13bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
c31c1dde 14 unsigned char Buf[64 * 64];
9ce3cfc9 15 bool const ToEOF = (Size == 0);
c31c1dde
DK
16 while (Size != 0 || ToEOF)
17 {
650faab0 18 unsigned long long n = sizeof(Buf);
8f3ba4e8 19 if (!ToEOF) n = std::min(Size, n);
9ce3cfc9 20 ssize_t const Res = read(Fd, Buf, n);
650faab0 21 if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
c31c1dde
DK
22 return false;
23 if (ToEOF && Res == 0) // EOF
24 break;
25 Size -= Res;
26 Add(Buf,Res);
27 }
28 return true;
109eb151
DK
29}
30bool SummationImplementation::AddFD(FileFd &Fd, unsigned long long Size) {
31 unsigned char Buf[64 * 64];
9ce3cfc9 32 bool const ToEOF = (Size == 0);
109eb151
DK
33 while (Size != 0 || ToEOF)
34 {
35 unsigned long long n = sizeof(Buf);
36 if (!ToEOF) n = std::min(Size, n);
37 unsigned long long a = 0;
38 if (Fd.Read(Buf, n, &a) == false) // error
39 return false;
40 if (ToEOF == false)
41 {
42 if (a != n) // short read
43 return false;
44 }
45 else if (a == 0) // EOF
46 break;
47 Size -= a;
48 Add(Buf, a);
49 }
50 return true;
c31c1dde
DK
51}
52 /*}}}*/