hashsum.cc 767 B

1234567891011121314151617181920212223242526272829
  1. // Cryptographic API Base
  2. #include <config.h>
  3. #include <unistd.h>
  4. #include "hashsum_template.h"
  5. // Summation::AddFD - Add content of file into the checksum /*{{{*/
  6. // ---------------------------------------------------------------------
  7. /* */
  8. bool SummationImplementation::AddFD(int const Fd, unsigned long long Size) {
  9. unsigned char Buf[64 * 64];
  10. ssize_t Res = 0;
  11. int ToEOF = (Size == 0);
  12. while (Size != 0 || ToEOF)
  13. {
  14. unsigned long long n = sizeof(Buf);
  15. if (!ToEOF) n = std::min(Size, n);
  16. Res = read(Fd, Buf, n);
  17. if (Res < 0 || (!ToEOF && Res != (ssize_t) n)) // error, or short read
  18. return false;
  19. if (ToEOF && Res == 0) // EOF
  20. break;
  21. Size -= Res;
  22. Add(Buf,Res);
  23. }
  24. return true;
  25. }
  26. /*}}}*/