File: openFile.h

package info (click to toggle)
graphviz 14.1.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 139,440 kB
  • sloc: ansic: 142,129; cpp: 11,960; python: 7,770; makefile: 4,043; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,388; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (19 lines) | stat: -rw-r--r-- 502 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <util/exit.h>

static inline FILE *openFile(const char *argv0, const char *name,
                             const char *mode) {
  FILE *fp = fopen(name, mode);
  if (fp == NULL) {
    const char *modestr = strcmp(mode, "r") == 0 ? "reading" : "writing";
    fprintf(stderr, "%s: could not open file %s for %s\n", argv0, name,
            modestr);
    perror(name);
    graphviz_exit(EXIT_FAILURE);
  }
  return fp;
}