hashsum.cc 738 B

12345678910111213141516171819202122232425262728
  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. while (Size != 0 || ToEOF)
  12. {
  13. unsigned n = sizeof(Buf);
  14. if (!ToEOF) n = min(Size,(unsigned long)n);
  15. Res = read(Fd, Buf, n);
  16. if (Res < 0 || (!ToEOF && (unsigned) Res != n)) // error, or short read
  17. return false;
  18. if (ToEOF && Res == 0) // EOF
  19. break;
  20. Size -= Res;
  21. Add(Buf,Res);
  22. }
  23. return true;
  24. }
  25. /*}}}*/