openFile.h 502 B

12345678910111213141516171819
  1. #pragma once
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <util/exit.h>
  6. static inline FILE *openFile(const char *argv0, const char *name,
  7. const char *mode) {
  8. FILE *fp = fopen(name, mode);
  9. if (fp == NULL) {
  10. const char *modestr = strcmp(mode, "r") == 0 ? "reading" : "writing";
  11. fprintf(stderr, "%s: could not open file %s for %s\n", argv0, name,
  12. modestr);
  13. perror(name);
  14. graphviz_exit(EXIT_FAILURE);
  15. }
  16. return fp;
  17. }