read_file_into.c 341 B

1234567891011121314151617181920
  1. /*
  2. * Read an entire file into a BinarySink.
  3. */
  4. #include <stdio.h>
  5. #include "defs.h"
  6. #include "misc.h"
  7. bool read_file_into(BinarySink *bs, FILE *fp)
  8. {
  9. char buf[4096];
  10. while (1) {
  11. size_t retd = fread(buf, 1, sizeof(buf), fp);
  12. if (retd == 0)
  13. return !ferror(fp);
  14. put_data(bs, buf, retd);
  15. }
  16. }