[PATCH rendercheck 1/2] Replace errx with fatal, and drop the err.h dependency.

Jesse Adkins jesserayadkins at gmail.com
Tue Oct 26 16:10:47 PDT 2010


errx is always called with eval being 1, so it's really just an overcomplicated
fprintf + exit. More importantly, err.h is not provided by Solaris 9.

Part 1 of a fix for #6611.

Signed-off-by: Jesse Adkins <jesserayadkins at gmail.com>
---
 configure.ac  |    1 -
 main.c        |   22 +++++++++++++++++-----
 rendercheck.h |   21 ++++-----------------
 tests.c       |   18 +++++++++---------
 4 files changed, 30 insertions(+), 32 deletions(-)

diff --git a/configure.ac b/configure.ac
index a71e53f..6470a5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,7 +24,6 @@ AC_PROG_SED
 
 # Checks for header files.
 AC_HEADER_STDC
-AC_CHECK_HEADERS([err.h])
 
 AC_ARG_ENABLE(werror,        AS_HELP_STRING([--enable-werror],
 				  [Treat warnings as errors (default: disabled)]),
diff --git a/main.c b/main.c
index 99d8441..17252fb 100644
--- a/main.c
+++ b/main.c
@@ -43,6 +43,18 @@ int pixmap_move_iter = 1;
 int win_width = 40;
 int win_height = 40;
 
+void fatal(const char *fmt, ...)
+{
+    va_list args;
+
+    va_start(args, fmt);
+    fprintf(stderr, "Fatal Error: ");
+    fprintf(stderr, fmt, args);
+    fputc('\n', stderr);
+    va_end(args);
+    exit(EXIT_FAILURE);
+}
+
 int
 bit_count(int i)
 {
@@ -178,7 +190,7 @@ int main(int argc, char **argv)
 			format_whitelist = malloc(sizeof(char *) *
 			    format_whitelist_len);
 			if (format_whitelist == NULL)
-				errx(1, "malloc");
+				fatal("malloc");
 
 			/* Now the list is separated by \0s, so use strlen to
 			 * step between entries.
@@ -249,16 +261,16 @@ int main(int argc, char **argv)
 
 	dpy = XOpenDisplay(display);
 	if (dpy == NULL)
-		errx(1, "Couldn't open display.");
+		fatal("Couldn't open display.");
 	if (is_sync)
 		XSynchronize(dpy, 1);
 
 	if (!XRenderQueryExtension(dpy, &i, &i))
-		errx(1, "Render extension missing.");
+		fatal("Render extension missing.");
 
 	XRenderQueryVersion(dpy, &maj, &min);
 	if (maj != 0 || min < 1)
-		errx(1, "Render extension version too low (%d.%d).", maj, min);
+		fatal("Render extension version too low (%d.%d).", maj, min);
 
 	printf("Render extension version %d.%d\n", maj, min);
 
@@ -282,7 +294,7 @@ int main(int argc, char **argv)
 	    window.format, 0, NULL);
 	window.name = (char *)malloc(20);
 	if (window.name == NULL)
-		errx(1, "malloc error");
+		fatal("malloc error");
 	describe_format(window.name, 20, window.format);
 	printf("Window format: %s\n", window.name);
 	strncat(window.name, " window", 20);
diff --git a/rendercheck.h b/rendercheck.h
index bb35c5e..6a5a0a7 100644
--- a/rendercheck.h
+++ b/rendercheck.h
@@ -23,23 +23,7 @@
 #include <X11/Xlib.h>
 #include <X11/extensions/Xrender.h>
 
-#if HAVE_ERR_H
-# include <err.h>
-#else
-# include <stdarg.h>
-# include <stdio.h>
-# include <stdlib.h>
-static inline void errx(int eval, const char *fmt, ...) {
-    va_list args;
-
-    va_start(args, fmt);
-    fprintf(stderr, "Fatal Error: ");
-    fprintf(stderr, fmt, args);
-    fprintf(stderr, "\n", args);
-    va_end(args);
-    exit(eval);
-}
-#endif
+#include <stdarg.h>
 
 #define min(a, b) (a < b ? a : b)
 #define max(a, b) (a > b ? a : b)
@@ -101,6 +85,9 @@ describe_format(char *desc, int len, XRenderPictFormat *format);
 int
 bit_count(int i);
 
+void
+fatal(const char *fmt, ...);
+
 /* tests.c */
 void
 color_correct(picture_info *pi, color4d *color);
diff --git a/tests.c b/tests.c
index 47a10dc..73b259a 100644
--- a/tests.c
+++ b/tests.c
@@ -215,7 +215,7 @@ create_formats_list(Display *dpy)
 
     format_list = malloc(sizeof(XRenderPictFormat *) * nformats_allocated);
     if (format_list == NULL)
-	errx(1, "malloc error");
+	fatal("malloc error");
     nformats = 0;
 
     argb32index = -1;
@@ -228,7 +228,7 @@ create_formats_list(Display *dpy)
 	    format_list = realloc(format_list, sizeof(XRenderPictFormat *) *
 		nformats_allocated);
 	    if (format_list == NULL)
-		errx(1, "realloc error");
+		fatal("realloc error");
 	}
 
 	format_list[nformats] = XRenderFindFormat(dpy, PictFormatType, &templ,
@@ -277,7 +277,7 @@ create_formats_list(Display *dpy)
 	nformats++;
     }
     if (argb32index == -1) {
-	errx(1, "required ARGB32 format not found");
+	fatal("required ARGB32 format not found");
     }
 }
 
@@ -295,7 +295,7 @@ do_tests(Display *dpy, picture_info *win)
 	num_dests = nformats;
 	dests = (picture_info *)malloc(num_dests * sizeof(dests[0]));
 	if (dests == NULL)
-		errx(1, "malloc error");
+		fatal("malloc error");
 
 	for (i = 0; i < num_dests; i++) {
 		dests[i].format = format_list[i];
@@ -306,14 +306,14 @@ do_tests(Display *dpy, picture_info *win)
 
 		dests[i].name = (char *)malloc(20);
 		if (dests[i].name == NULL)
-			errx(1, "malloc error");
+			fatal("malloc error");
 		describe_format(dests[i].name, 20, dests[i].format);
 	}
 
 	pictures_1x1 = (picture_info *)malloc(num_colors * nformats *
 	    sizeof(picture_info));
 	if (pictures_1x1 == NULL)
-		errx(1, "malloc error");
+		fatal("malloc error");
 
 	for (i = 0; i < num_colors * nformats; i++) {
 		XRenderPictureAttributes pa;
@@ -329,7 +329,7 @@ do_tests(Display *dpy, picture_info *win)
 
 		pictures_1x1[i].name = (char *)malloc(20);
 		if (pictures_1x1[i].name == NULL)
-			errx(1, "malloc error");
+			fatal("malloc error");
 		sprintf(pictures_1x1[i].name, "1x1R ");
 		describe_format(pictures_1x1[i].name +
 		    strlen(pictures_1x1[i].name), 20 -
@@ -349,7 +349,7 @@ do_tests(Display *dpy, picture_info *win)
 	pictures_10x10 = (picture_info *)malloc(num_colors * nformats *
 	    sizeof(picture_info));
 	if (pictures_10x10 == NULL)
-		errx(1, "malloc error");
+		fatal("malloc error");
 
 	for (i = 0; i < num_colors * nformats; i++) {
 		XRenderPictureAttributes pa;
@@ -365,7 +365,7 @@ do_tests(Display *dpy, picture_info *win)
 
 		pictures_10x10[i].name = (char *)malloc(20);
 		if (pictures_10x10[i].name == NULL)
-			errx(1, "malloc error");
+			fatal("malloc error");
 		sprintf(pictures_10x10[i].name, "10x10 ");
 		describe_format(pictures_10x10[i].name +
 		    strlen(pictures_10x10[i].name), 20 -
-- 
1.7.1



More information about the xorg-devel mailing list