[PATCH v4 7/7] Convert cvt code to use XNFasprintf()

Alan Coopersmith alan.coopersmith at oracle.com
Sat Dec 4 12:14:41 PST 2010


Requires linking xprintf.c into standalone cvt utility

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
Reviewed-by: Mikhail Gusarov <dottedmag at dottedmag.net>
Reviewed-by: Julien Cristau <jcristau at debian.org>
---
 hw/xfree86/modes/xf86cvt.c       |   10 +---------
 hw/xfree86/utils/cvt/Makefile.am |    5 ++++-
 hw/xfree86/utils/cvt/cvt.c       |   18 ++++++++++++++++++
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/hw/xfree86/modes/xf86cvt.c b/hw/xfree86/modes/xf86cvt.c
index 1da5fe5..244f3b9 100644
--- a/hw/xfree86/modes/xf86cvt.c
+++ b/hw/xfree86/modes/xf86cvt.c
@@ -279,15 +279,7 @@ xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
     if (Interlaced)
         Mode->VTotal *= 2;
 
-    {
-        char  Name[256];
-        Name[0] = 0;
-
-        snprintf(Name, 256, "%dx%d", HDisplay, VDisplay);
-
-        Mode->name = xnfalloc(strlen(Name) + 1);
-        memcpy(Mode->name, Name, strlen(Name) + 1);
-    }
+    XNFasprintf(&Mode->name, "%dx%d", HDisplay, VDisplay);
 
     if (Reduced)
         Mode->Flags |= V_PHSYNC | V_NVSYNC;
diff --git a/hw/xfree86/utils/cvt/Makefile.am b/hw/xfree86/utils/cvt/Makefile.am
index 0658682..ba02145 100644
--- a/hw/xfree86/utils/cvt/Makefile.am
+++ b/hw/xfree86/utils/cvt/Makefile.am
@@ -27,7 +27,10 @@ INCLUDES = $(XORG_INCS) \
 	   -I$(top_srcdir)/hw/xfree86/parser
 
 # gah
-cvt_SOURCES = cvt.c $(top_srcdir)/hw/xfree86/modes/xf86cvt.c
+cvt_SOURCES = cvt.c \
+	$(top_srcdir)/hw/xfree86/modes/xf86cvt.c \
+	$(top_srcdir)/os/xprintf.c
+
 cvt_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
 
 man1_MANS = cvt.man
diff --git a/hw/xfree86/utils/cvt/cvt.c b/hw/xfree86/utils/cvt/cvt.c
index cf0a479..fff500b 100644
--- a/hw/xfree86/utils/cvt/cvt.c
+++ b/hw/xfree86/utils/cvt/cvt.c
@@ -25,6 +25,24 @@
 
 #include "xf86.h"
 
+/* Error implementation used by the server code we built in */
+void
+Error(const char *str)
+{
+    perror(str);
+}
+
+/* FatalError implementation used by the server code we built in */
+void
+FatalError(const char *f, ...)
+{
+    va_list args;
+    va_start(args, f);
+    vfprintf(stderr, f, args);
+    va_end(args);
+    exit(1);
+}
+
 /* xnfalloc implementation used by the server code we built in */
 pointer
 XNFalloc(unsigned long n)
-- 
1.7.3.2



More information about the xorg-devel mailing list