]>
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; | |
27 | } | |
28 | /*}}}*/ |