test.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* xdelta3 - delta compression tools and library
  2. Copyright 2016 Joshua MacDonald
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #define NOT_MAIN 1
  14. #include "xdelta3.h"
  15. #include "xdelta3.c"
  16. static int read_whole_file(const char *name,
  17. uint8_t **buf_ptr,
  18. size_t *buf_len) {
  19. main_file file;
  20. int ret;
  21. xoff_t len;
  22. usize_t nread;
  23. main_file_init(&file);
  24. file.filename = name;
  25. ret = main_file_open(&file, name, XO_READ);
  26. if (ret != 0) {
  27. fprintf(stderr, "open failed\n");
  28. goto exit;
  29. }
  30. ret = main_file_stat(&file, &len);
  31. if (ret != 0) {
  32. fprintf(stderr, "stat failed\n");
  33. goto exit;
  34. }
  35. (*buf_len) = (size_t)len;
  36. (*buf_ptr) = (uint8_t*) main_malloc(*buf_len);
  37. ret = main_file_read(&file, *buf_ptr, *buf_len, &nread,
  38. "read failed");
  39. if (ret == 0 && *buf_len == nread) {
  40. ret = 0;
  41. } else {
  42. fprintf(stderr, "invalid read\n");
  43. ret = XD3_INTERNAL;
  44. }
  45. exit:
  46. main_file_cleanup(&file);
  47. return ret;
  48. }