]> git.saurik.com Git - apt.git/blame - apt-pkg/contrib/hashsum.cc
disable https->http redirects in libcurl
[apt.git] / apt-pkg / contrib / hashsum.cc
CommitLineData
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 10bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
c31c1dde 11 unsigned char Buf[64 * 64];
9ce3cfc9 12 bool const ToEOF = (Size == 0);
c31c1dde
DK
13 while (Size != 0 || ToEOF)
14 {
650faab0 15 unsigned long long n = sizeof(Buf);
8f3ba4e8 16 if (!ToEOF) n = std::min(Size, n);
9ce3cfc9 17 ssize_t const Res = read(Fd, Buf, n);
650faab0 18 if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
c31c1dde
DK
19 return false;
20 if (ToEOF && Res == 0) // EOF
21 break;
22 Size -= Res;
23 Add(Buf,Res);
24 }
25 return true;
109eb151
DK
26}
27bool SummationImplementation::AddFD(FileFd &Fd, unsigned long long Size) {
28 unsigned char Buf[64 * 64];
9ce3cfc9 29 bool const ToEOF = (Size == 0);
109eb151
DK
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;
c31c1dde
DK
48}
49 /*}}}*/