]>
git.saurik.com Git - apt.git/blob - apt-pkg/contrib/hashsum.cc
1 // Cryptographic API Base
4 #include <apt-pkg/fileutl.h>
8 #include "hashsum_template.h"
10 // Summation::AddFD - Add content of file into the checksum /*{{{*/
11 // ---------------------------------------------------------------------
13 bool SummationImplementation::AddFD(int const Fd
, unsigned long long Size
) {
14 unsigned char Buf
[64 * 64];
15 bool const ToEOF
= (Size
== 0);
16 while (Size
!= 0 || ToEOF
)
18 unsigned long long n
= sizeof(Buf
);
19 if (!ToEOF
) n
= std::min(Size
, n
);
20 ssize_t
const Res
= read(Fd
, Buf
, n
);
21 if (Res
< 0 || (!ToEOF
&& Res
!= (ssize_t
) n
)) // error, or short read
23 if (ToEOF
&& Res
== 0) // EOF
30 bool SummationImplementation::AddFD(FileFd
&Fd
, unsigned long long Size
) {
31 unsigned char Buf
[64 * 64];
32 bool const ToEOF
= (Size
== 0);
33 while (Size
!= 0 || ToEOF
)
35 unsigned long long n
= sizeof(Buf
);
36 if (!ToEOF
) n
= std::min(Size
, n
);
37 unsigned long long a
= 0;
38 if (Fd
.Read(Buf
, n
, &a
) == false) // error
42 if (a
!= n
) // short read
45 else if (a
== 0) // EOF