Commits

Shlomi Fish committed 35e9e7e

Got rid of some functions in util.[ch].

Comments (0)

Files changed (4)

 
 	/* Now print them out in the correct order. */
 
-	out = fileopen("win", "w");
+	out = fopen("win", "w");
+
+    if (! out)
+    {
+        fprintf(stderr, "%s\n", "Cannot open 'win' for writing.");
+        exit(1);
+    }
 	for (i = 0, mpp = mpp0; i < nmoves; i++, mpp++) {
 		mp = *mpp;
 		printcard(mp->card, out);

patsolve/patmain.c

 
 #include <ctype.h>
 #include <signal.h>
+#include <stdarg.h>
 #include "pat.h"
 #include "tree.h"
 
 #if DEBUG
 long Init_mem_remain;
 #endif
+
+static char *Progname = NULL;
+
+/* Print a message and exit. */
+static void fatalerr(char *msg, ...)
+{
+	va_list ap;
+
+	if (Progname) {
+		fprintf(stderr, "%s: ", Progname);
+	}
+	va_start(ap, msg);
+	vfprintf(stderr, msg, ap);
+	va_end(ap);
+	fputc('\n', stderr);
+
+	exit(1);
+}
+
 void set_param(fc_solve_soft_thread_t * soft_thread, int pnum)
 {
 	const int *x;
 
 	infile = stdin;
 	if (argc && **argv != '-') {
-		infile = fileopen(*argv, "r");
+		infile = fopen(*argv, "r");
+
+        if (! infile)
+        {
+            fatalerr("Cannot open input file '%s' (for reading).", *argv);
+        }
 	}
 
 	/* Initialize the suitable() macro variables. */
  */
 /* Standard utilities. */
 
+#include <stdarg.h>
+
 #include "util.h"
 #include "pat.h"
 
-char *Progname = NULL;
-
-/* Print a message and exit. */
-
-void fatalerr(char *msg, ...)
-{
-	va_list ap;
-
-	if (Progname) {
-		fprintf(stderr, "%s: ", Progname);
-	}
-	va_start(ap, msg);
-	vfprintf(stderr, msg, ap);
-	va_end(ap);
-	fputc('\n', stderr);
-
-	exit(1);
-}
-
 /* Just print a message. */
 
 void msg(char *msg, ...)
 	va_end(ap);
 }
 
-/* Open a file or exit on failure. */
-
-FILE *fileopen(char *name, char *mode)
-{
-	FILE *f;
-
-	if ((f = fopen(name, mode)) == NULL) {
-		fatalerr("can't %s '%s'", *mode == 'r' ? "open" : "write", name);
-	}
-	return f;
-}
-
 /* Like strcpy() but return the length of the string. */
 
 int strecpy(u_char *dest, u_char *src)
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <string.h>
 #include <math.h>
 
 extern void free_blocks(void);
 
 /* Error messages. */
-
-extern char *Progname;
-extern void fatalerr(char *msg, ...);
 extern void msg(char *msg, ...);
 
 /* Files. */
 
-extern FILE *fileopen(char *name, char *mode);
-
 /* Misc. */
 
 extern int strecpy(u_char *dest, u_char *src);