bin_file_read.cpp 855 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/bin_file.h>
  5. #include<__vic/windows/throw_last_error.h>
  6. #include<windows.h>
  7. namespace __vic {
  8. //----------------------------------------------------------------------------
  9. size_t bin_file::read_some(void *buf, size_t n)
  10. {
  11. DWORD read;
  12. if(!::ReadFile(hFile, buf, n, &read, nullptr))
  13. windows::throw_last_error("ReadFile");
  14. return read;
  15. }
  16. //----------------------------------------------------------------------------
  17. size_t bin_file::read_max(void *buf, size_t n)
  18. {
  19. size_t res = 0;
  20. do {
  21. DWORD read;
  22. if(!::ReadFile(hFile, buf, n, &read, nullptr))
  23. windows::throw_last_error("ReadFile");
  24. if(read == 0) break;
  25. res += read;
  26. } while(res < n);
  27. return res;
  28. }
  29. //----------------------------------------------------------------------------
  30. } // namespace