]> git.saurik.com Git - apt.git/blame_incremental - apt-pkg/contrib/hashsum.cc
warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
[apt.git] / apt-pkg / contrib / hashsum.cc
... / ...
CommitLineData
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/* */
10bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
11 unsigned char Buf[64 * 64];
12 bool const ToEOF = (Size == 0);
13 while (Size != 0 || ToEOF)
14 {
15 unsigned long long n = sizeof(Buf);
16 if (!ToEOF) n = std::min(Size, n);
17 ssize_t const Res = read(Fd, Buf, n);
18 if (Res < 0 || (!ToEOF && Res != (ssize_t) 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}
27bool SummationImplementation::AddFD(FileFd &Fd, unsigned long long Size) {
28 unsigned char Buf[64 * 64];
29 bool const ToEOF = (Size == 0);
30 while (Size != 0 || ToEOF)
31 {
32 unsigned long long n = sizeof(Buf);
33 if (!ToEOF) n = std::min(Size, n);
34 unsigned long long a = 0;
35 if (Fd.Read(Buf, n, &a) == false) // error
36 return false;
37 if (ToEOF == false)
38 {
39 if (a != n) // short read
40 return false;
41 }
42 else if (a == 0) // EOF
43 break;
44 Size -= a;
45 Add(Buf, a);
46 }
47 return true;
48}
49 /*}}}*/