It's a stack calculator for the unwise. Public Domain.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

27 lines
477B

  1. static inline size_t
  2. frem(FILE * fp)
  3. {
  4. fseek(fp, 0, SEEK_END);
  5. return ftell(fp);
  6. }
  7. static char *
  8. slurp(const char * fn, size_t * rlen)
  9. {
  10. size_t len;
  11. FILE * fp = fopen(fn, "r");
  12. char * buf;
  13. if (!fp)
  14. { PERROR_RETURN("fopen", NULL); }
  15. if (!(buf = (char *) malloc((len = frem(fp)))))
  16. { PERROR_RETURN("malloc", NULL); }
  17. rewind(fp);
  18. if (len != fread(buf, 1, len, fp))
  19. {
  20. free(buf);
  21. { PERROR_RETURN("fopen", NULL); }
  22. }
  23. *rlen = len;
  24. return buf;
  25. }