hashsum.cc 734 B

1234567891011121314151617181920212223242526272829
  1. // Cryptographic API Base
  2. #include <unistd.h>
  3. #include "hashsum_template.h"
  4. // Summation::AddFD - Add content of file into the checksum /*{{{*/
  5. // ---------------------------------------------------------------------
  6. /* */
  7. bool SummationImplementation::AddFD(int const Fd, unsigned long Size) {
  8. unsigned char Buf[64 * 64];
  9. int Res = 0;
  10. int ToEOF = (Size == 0);
  11. unsigned long n = sizeof(Buf);
  12. if (!ToEOF)
  13. n = std::min(Size, n);
  14. while (Size != 0 || ToEOF)
  15. {
  16. Res = read(Fd, Buf, n);
  17. if (Res < 0 || (!ToEOF && (unsigned) Res != 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. /*}}}*/