[rtems commit] dumpbuf: Simplify rtems_print_buffer()

Sebastian Huber sebh at rtems.org
Tue Jul 18 12:25:34 UTC 2017


Module:    rtems
Branch:    master
Commit:    b682f4cb2186c0cf1212bb828a5795a9c84ef7d6
Changeset: http://git.rtems.org/rtems/commit/?id=b682f4cb2186c0cf1212bb828a5795a9c84ef7d6

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Jul 18 13:03:41 2017 +0200

dumpbuf: Simplify rtems_print_buffer()

This avoids an unnecessary use of the floating point unit.

Update #3076.

---

 cpukit/libmisc/dumpbuf/dumpbuf.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/cpukit/libmisc/dumpbuf/dumpbuf.c b/cpukit/libmisc/dumpbuf/dumpbuf.c
index 2f2cd10..a27d685 100644
--- a/cpukit/libmisc/dumpbuf/dumpbuf.c
+++ b/cpukit/libmisc/dumpbuf/dumpbuf.c
@@ -70,6 +70,8 @@ void rtems_print_buffer(const unsigned char *buffer, const int length)
   }
 }
 
+static char const hexlist[] = "0123456789abcdef";
+
 /**
  * @brief Print \p length bytes from \p buffer, both in hex and ASCII.
  * @details Non-printable chars will appear as dots.
@@ -80,35 +82,39 @@ void rtems_print_buffer(const unsigned char *buffer, const int length)
 static void Dump_Line(const unsigned char *buffer, const unsigned int length)
 {
   unsigned int i;
-  static char line_buffer[ROW_LENGTH] = "";
-  size_t tmp_len;
 
   /* Output the hex value of each byte. */
   for (i = 0; i < length; ++i) {
-    snprintf(&line_buffer[i * HEX_FMT_LENGTH], HEX_FMT_LENGTH + 1,
-             "%02x ", buffer[i]);
+    unsigned char c = buffer[i];
+
+    rtems_putc(hexlist[(c >> 4) & 0xf]);
+    rtems_putc(hexlist[0xf]);
+    rtems_putc(' ');
   }
 
   /* Fill the remaining space with whitespace (if necessary). */
   for (; i < BYTES_PER_ROW; ++i) {
-    strncat(line_buffer, "   ", HEX_FMT_LENGTH);
+    rtems_putc(' ');
+    rtems_putc(' ');
+    rtems_putc(' ');
   }
 
   /* Append a bar. */
-  strncat(line_buffer, "|", 1);
-  tmp_len = strnlen(line_buffer, ROW_LENGTH);
+  rtems_putc('|');
 
   /* Now output the ASCII glyphs of printable chars. */
   for (i = 0; i < length; ++i) {
-    snprintf(&line_buffer[tmp_len + i], ASCII_FMT_LENGTH + 1,
-             "%c", isprint(buffer[i]) ? buffer[i] : '.');
+    unsigned char c = buffer[i];
+
+    rtems_putc(isprint(c) ? c : '.');
   }
 
   /* Fill the remaining space with whitespace (if necessary). */
   for(; i < BYTES_PER_ROW; i++) {
-    strncat(line_buffer, " ", ASCII_FMT_LENGTH);
+    rtems_putc(' ');
   }
 
   /* Append another bar and print the resulting string. */
-  printk("%s|\n", line_buffer);
+  rtems_putc('|');
+  rtems_putc('\n');
 }



More information about the vc mailing list