diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-07-18 13:03:41 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-07-18 14:13:48 +0200 |
commit | b682f4cb2186c0cf1212bb828a5795a9c84ef7d6 (patch) | |
tree | 783c26acda383ff7487f02c5ced5eaa5dcca5564 | |
parent | tests: Use more integer print functions (diff) | |
download | rtems-b682f4cb2186c0cf1212bb828a5795a9c84ef7d6.tar.bz2 |
dumpbuf: Simplify rtems_print_buffer()
This avoids an unnecessary use of the floating point unit.
Update #3076.
-rw-r--r-- | cpukit/libmisc/dumpbuf/dumpbuf.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/cpukit/libmisc/dumpbuf/dumpbuf.c b/cpukit/libmisc/dumpbuf/dumpbuf.c index 2f2cd10895..a27d685f72 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'); } |