file_utils.cpp 835 B

1234567891011121314151617181920212223242526272829
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 Jérémie Dumas <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "file_utils.h"
  9. #include <cstring>
  10. namespace igl {
  11. IGL_INLINE void read_file_binary(FILE *fp,
  12. std::vector<uint8_t> &fileBufferBytes) {
  13. if (!ferror(fp)) {
  14. fseek(fp, 0, SEEK_END);
  15. size_t sizeBytes = ftell(fp);
  16. fseek(fp, 0, SEEK_SET);
  17. fileBufferBytes.resize(sizeBytes);
  18. if (fread((char *)fileBufferBytes.data(), 1, sizeBytes, fp) == sizeBytes)
  19. return;
  20. }
  21. throw std::runtime_error("error reading from file");
  22. }
  23. }