[PATCH 4/4] teach fatal() to write newline

Jonathan Nieder jrnieder at gmail.com
Fri Dec 2 14:36:51 PST 2011


This is more robust: if a caller forgets the final newline, the
resulting messages that run together can be hard to read, whereas if a
caller adds an extra newline, it just means an extra blank line in the
output.

Rename the function when changing the interface so any callers that
have not been adjusted will break the build.  No change in
functionality intended.

Signed-off-by: Jonathan Nieder <jrnieder at gmail.com>
---
 avivotool.c  |   28 ++++++++++++++--------------
 radeonreg.c  |   14 +++++++-------
 radeontool.c |   20 ++++++++++----------
 3 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/avivotool.c b/avivotool.c
index 2b710772..7626f705 100644
--- a/avivotool.c
+++ b/avivotool.c
@@ -62,9 +62,9 @@ unsigned char * volatile ctrl_mem;
 unsigned char * volatile fb_mem;
 
 
-static void fatal(char *why)
+static void die(const char *why)
 {
-    fprintf(stderr, "fatal error: %s", why);
+    fprintf(stderr, "fatal error: %s\n", why);
     pci_system_cleanup();
 
 }
@@ -75,7 +75,7 @@ static void radeon_set(unsigned long offset, const char *name, unsigned int valu
         printf("writing %s (%lx) -> %08x\n", name, offset, value);
 
     if (ctrl_mem == NULL)
-        fatal("internal error\n");
+        die("internal error");
 
 #ifdef __powerpc__
     __asm__ __volatile__ ("stwbrx %1,%2,%3\n\t"
@@ -103,7 +103,7 @@ static unsigned int radeon_get(unsigned long offset, const char *name)
         printf("reading %s (%lx) is ", name, offset);
 
     if (ctrl_mem == NULL)
-        fatal("internal error\n");
+        die("internal error");
 
 #ifdef __powerpc__
     __asm__ __volatile__ ("lwbrx %0,%1,%2\n\t"
@@ -615,7 +615,7 @@ void radeon_output_set(char *output, char *status)
 #endif
     }
     else {
-        fatal("unknown output\n");
+        die("unknown output");
     }
 }
 
@@ -662,7 +662,7 @@ void radeon_dump_img(char *type)
     unsigned char * volatile fb;
     
     if (!radeon_get_fb_params(type, 0, &location, &len) || !len)
-        fatal("mapping location to dump\n");
+        die("mapping location to dump");
 
     fb = (unsigned char * volatile) location;
 
@@ -671,7 +671,7 @@ void radeon_dump_img(char *type)
         ret = write(STDOUT_FILENO, &(fb[i]), len - i);
         if (ret < 0) {
             fprintf(stderr, "write died: %s\n", strerror(errno));
-            fatal("writing to stdout\n");
+            die("writing to stdout");
         }
         i += ret;
     }
@@ -686,10 +686,10 @@ void radeon_load_img(char *type)
     unsigned char * volatile fb;
     
     if (!radeon_get_fb_params(type, 1, &location, &len))
-        fatal("mapping framebuffer to load\n");
+        die("mapping framebuffer to load");
 
     if (!len)
-        fatal("mapping framebuffer to load\n");
+        die("mapping framebuffer to load");
     fb = (unsigned char * volatile) location;
 
     i = 0;
@@ -697,7 +697,7 @@ void radeon_load_img(char *type)
         ret = read(STDIN_FILENO, &(fb[i]), len - i);
         if (ret < 0) {
             fprintf(stderr, "read died: %s\n", strerror(errno));
-            fatal("reading from stdin\n");
+            die("reading from stdin");
         }
         i += ret;
     }
@@ -1706,7 +1706,7 @@ static int map_radeon_mem(void)
     int i = 0;
 
     if (pci_system_init() != 0)
-        fatal("failed to initialise libpciaccess\n");
+        die("failed to initialise libpciaccess");
 
 #if 0
     match.vendor_id = 0x1002;
@@ -1772,7 +1772,7 @@ static int map_radeon_mem(void)
     }
       
     if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0)
-        fatal("mapping ctrl region\n");
+        die("mapping ctrl region");
     ctrl_mem = avivo_device->regions[ctrl_region].memory;
 
     if (pci_device_map_region(avivo_device, fb_region, 1) == 0)
@@ -2166,7 +2166,7 @@ void radeon_rom_tables(const char * file)
     }
 
     if (bios[0] != 0x55 || bios[1] != 0xaa)
-        fatal("PCI ROM signature 0x55 0xaa missing\n");
+        die("PCI ROM signature 0x55 0xaa missing");
 
     hdr = BIOS16(0x48);
     printf("\nBIOS Tables:\n------------\n\n");	
@@ -2243,7 +2243,7 @@ int main(int argc, char *argv[])
     ret = map_radeon_mem();
     if (strcmp(argv[1], "romtables") != 0) {
       if (ret!=0)
-	fatal("Unable to see card\n");
+	die("Unable to see card");
     }
 
     if (argc == 2) {
diff --git a/radeonreg.c b/radeonreg.c
index a1329dbe..70c27fd4 100644
--- a/radeonreg.c
+++ b/radeonreg.c
@@ -45,9 +45,9 @@ unsigned char * volatile ctrl_mem;
 unsigned char * volatile fb_mem;
 
 
-static void fatal(char *why)
+static void die(const char *why)
 {
-    fprintf(stderr, "fatal error: %s", why);
+    fprintf(stderr, "fatal error: %s\n", why);
     pci_system_cleanup();
 
 }
@@ -56,7 +56,7 @@ static void radeon_set(unsigned long offset, const char *name, unsigned int valu
 {
 
     if (ctrl_mem == NULL)
-        fatal("internal error\n");
+        die("internal error");
 
 #ifdef __powerpc__
     __asm__ __volatile__ ("stwbrx %1,%2,%3\n\t"
@@ -81,7 +81,7 @@ static unsigned int radeon_get(unsigned long offset, const char *name)
     unsigned int value;
 
     if (ctrl_mem == NULL)
-        fatal("internal error\n");
+        die("internal error");
 
 #ifdef __powerpc__
     __asm__ __volatile__ ("lwbrx %0,%1,%2\n\t"
@@ -368,7 +368,7 @@ static int map_radeon_mem(void)
     int i = 0;
 
     if (pci_system_init() != 0)
-        fatal("failed to initialise libpciaccess\n");
+        die("failed to initialise libpciaccess");
 
 #if 0
     match.vendor_id = 0x1002;
@@ -414,7 +414,7 @@ static int map_radeon_mem(void)
     }
 
     if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0)
-        fatal("mapping ctrl region\n");
+        die("mapping ctrl region");
     ctrl_mem = avivo_device->regions[ctrl_region].memory;
 
     if (pci_device_map_region(avivo_device, fb_region, 1) == 0)
@@ -442,7 +442,7 @@ int main(int argc, char *argv[])
 
     ret = map_radeon_mem();
     if (ret!=0)
-	    fatal("Unable to see card\n");
+	    die("Unable to see card");
 
     if (argc == 2) {
 	    if (strcmp(argv[1], "regs") == 0) {
diff --git a/radeontool.c b/radeontool.c
index 25343b3d..d2592545 100644
--- a/radeontool.c
+++ b/radeontool.c
@@ -37,9 +37,9 @@ int ctrl_region = -1, fb_region = -1;
 unsigned char * volatile fb_mem;
 unsigned char * volatile ctrl_mem;
 static void radeon_rom_legacy_mmio_table(unsigned char *bios, int offset);
-static void fatal(char *why)
+static void die(const char *why)
 {
-    fprintf(stderr, "fatal error: %s", why);
+    fprintf(stderr, "fatal error: %s\n", why);
     pci_system_cleanup();
     exit(-1);
 }
@@ -920,7 +920,7 @@ static void map_radeon_cntl_mem(void)
     int i = 0;
 
     if (pci_system_init() != 0)
-        fatal("failed to initialise libpciaccess\n");
+        die("failed to initialise libpciaccess");
 
     match.domain = PCI_MATCH_ANY;
     match.bus = PCI_MATCH_ANY;
@@ -946,28 +946,28 @@ static void map_radeon_cntl_mem(void)
                 if (device->regions[i].size >= 16 * 1024 &&
                     device->regions[i].size <= 64 * 1024) {
                     if (ctrl_region != -1)
-                        fatal("cannot distinguish ctrl region\n");
+                        die("cannot distinguish ctrl region");
                     ctrl_region = i;
                 } else if (device->regions[i].size >= 64 * 1024 * 1024) {
                     if (fb_region != -1)
-                        fatal("cannot distinguish fb region\n");
+                        die("cannot distinguish fb region");
                     fb_region = i;
                 }
             }
             if (ctrl_region == -1)
-                fatal("cannot find ctrl region\n");
+                die("cannot find ctrl region");
             if (fb_region == -1)
-                fatal("cannot find fb region\n");
+                die("cannot find fb region");
             avivo_device = device;
             break;
         }
     }
 
     if (!avivo_device)
-        fatal("cannot find Radeon device\n");
+        die("cannot find Radeon device");
 
     if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0)
-        fatal("mapping ctrl region\n");
+        die("mapping ctrl region");
     ctrl_mem = avivo_device->regions[ctrl_region].memory;
 
     if (pci_device_map_region(avivo_device, fb_region, 1) == 0)
@@ -2879,7 +2879,7 @@ void radeon_rom_tables(const char * file)
 	close(fd);
 
 	if (bios[0] != 0x55 || bios[1] != 0xaa)
-		fatal("PCI ROM signature 0x55 0xaa missing\n");
+		die("PCI ROM signature 0x55 0xaa missing");
 	hdr = BIOS16(0x48);
 	printf("\nBIOS Tables:\n------------\n\n");	
 	printf("Header at %x, type: %d [%s]\n", hdr, BIOS8(hdr),
-- 
1.7.8.rc3



More information about the xorg-driver-ati mailing list