Debian Codegraph @

cmd/tools/openFile.h

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