]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/hashsum.cc
1 // Cryptographic API Base
5 #include "hashsum_template.h"
7 // Summation::AddFD - Add content of file into the checksum /*{{{*/
8 // ---------------------------------------------------------------------
10 bool 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
)
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
20 if (ToEOF
&& Res
== 0) // EOF
27 bool 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
)
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
39 if (a
!= n
) // short read
42 else if (a
== 0) // EOF