]>
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];
13 int ToEOF
= (Size
== 0);
14 while (Size
!= 0 || ToEOF
)
16 unsigned long long n
= sizeof(Buf
);
17 if (!ToEOF
) n
= std::min(Size
, n
);
18 Res
= read(Fd
, Buf
, n
);
19 if (Res
< 0 || (!ToEOF
&& Res
!= (ssize_t
) n
)) // error, or short read
21 if (ToEOF
&& Res
== 0) // EOF
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
)
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
40 if (a
!= n
) // short read
43 else if (a
== 0) // EOF