]> granicus.if.org Git - graphviz/commitdiff
gxl2gv: dedupe 'openFile' implementation smattr/e1c72f1c-35a1-4064-8d9d-c1724e371e5b
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 10 Oct 2022 02:57:56 +0000 (19:57 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 10 Oct 2022 02:57:56 +0000 (19:57 -0700)
I am not sure why this was not done as part of
7d5fcee02fe8a046c2ed8801426c1a1afda3f80b.

cmd/tools/cvtgxl.c

index 2ce7d34859d6303937b183e0bbdd1583a4ed60cf..dbe7a30d89cf05937e24f30c4ebaada87ba961bd 100644 (file)
@@ -28,6 +28,7 @@
 #include "convert.h"
 #include <cgraph/exit.h>
 #include <ingraphs/ingraphs.h>
+#include "openFile.h"
 
 typedef enum { Unset, ToGV, ToGXL } mode;
 
@@ -62,19 +63,6 @@ static FILE *getFile(void)
 }
 #endif
 
-static FILE *openFile(const char *name)
-{
-    FILE *fp;
-
-    fp = fopen(name, "w");
-    if (!fp) {
-       fprintf(stderr, "%s: could not open file %s for writing\n", CmdName, name);
-       perror(name);
-       graphviz_exit(1);
-    }
-    return fp;
-}
-
 static const char *use = "Usage: %s [-gd?] [-o<file>] [<graphs>]\n\
  -g        : convert to GXL\n\
  -d        : convert to GV\n\
@@ -151,7 +139,7 @@ static void initargs(int argc, char **argv)
        case 'o':
            if (outFile != NULL)
                fclose(outFile);
-           outFile = openFile(optarg);
+           outFile = openFile(CmdName, optarg, "w");
            break;
        case ':':
            fprintf(stderr, "%s: option -%c missing argument\n", CmdName, optopt);