shithub: rgbds

Download patch

ref: 02ba30f8e0f93af7a24cc09f7260a78187a50277
parent: aea1990de311307ed0a05a68b5ba37c5d07c0b8e
author: bentley <[email protected]>
date: Mon Jan 18 11:47:08 EST 2010

rgblink: improve file open error messages

--- a/src/link/mapfile.c
+++ b/src/link/mapfile.c
@@ -1,7 +1,9 @@
 #include <err.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sysexits.h>
 
 #include "asmotor.h"
 
@@ -19,8 +21,9 @@
 {
 	mf = fopen(name, "w");
 
-	if (!mf)
-		errx(5, "Unable to open mapfile for writing");
+	if (mf == NULL)
+		errx(EX_CANTCREAT, "Cannot open mapfile '%s' : %s", name,
+		    strerror(errno));
 }
 
 void 
@@ -28,8 +31,9 @@
 {
 	sf = fopen(name, "w");
 
-	if (!sf)
-		errx(5, "Unable to open symfile for writing");
+	if (sf == NULL)
+		errx(EX_CANTCREAT, "Cannot open symfile '%' : %s", name,
+		    strerror(errno));
 
 	fprintf(sf, ";File generated by xLink v" LINK_VERSION "\n\n");
 }
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -4,9 +4,11 @@
  */
 
 #include <err.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sysexits.h>
 
 #include "link/mylink.h"
 #include "link/main.h"
@@ -443,9 +445,9 @@
 		oReadLib = 0;
 
 	pObjfile = fopen(tzObjectfile, "rb");
-	if (!pObjfile) {
-		errx(5, "Unable to open '%s'", tzObjectfile);
-	}
+	if (pObjfile == NULL)
+		errx(EX_NOINPUT, "Unable to open object '%s' : %s",
+		    tzObjectfile, strerror(errno));
 	obj_ReadOpenFile(pObjfile, tzObjectfile);
 	fclose(pObjfile);
 
@@ -493,6 +495,9 @@
 	oReadLib = 1;
 
 	pObjfile = fopen(tzLibfile, "rb");
+	if (pObjfile == NULL)
+		errx(EX_NOINPUT, "Unable to open object '%s' : %s",
+		    tzObjectfile, strerror(errno));
 	if (!pObjfile) {
 		errx(5, "Unable to open '%s'", tzLibfile);
 	}