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