]> granicus.if.org Git - strace/commitdiff
scsi.c: use print_array function
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 7 May 2016 23:10:50 +0000 (23:10 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 7 May 2016 23:37:53 +0000 (23:37 +0000)
* scsi.c (print_uchar): New function.
(print_sg_io_buffer): Use it via print_array.

scsi.c

diff --git a/scsi.c b/scsi.c
index 9038c3c9a56785d28f6829ae9d8e9d08b1e20723..01c5db2f6a9ab2df29aefb9cdb669d0af47de8c0 100644 (file)
--- a/scsi.c
+++ b/scsi.c
 #  include "xlat/bsg_subprotocol.h"
 # endif
 
+static bool
+print_uchar(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
+{
+       tprintf("%02x", (unsigned int) (* (unsigned char *) elem_buf));
+
+       return true;
+}
+
 static void
-print_sg_io_buffer(struct tcb *tcp, unsigned long addr, const unsigned int len)
+print_sg_io_buffer(struct tcb *tcp, const unsigned long addr, const unsigned int len)
 {
-       unsigned char *buf = NULL;
-       unsigned int allocated, i;
-
-       tprints("[");
-       if (len == 0)
-               goto out;
-       allocated = (len > max_strlen) ? max_strlen : len;
-       buf = malloc(allocated);
-       if (!buf || umoven(tcp, addr, allocated, buf) < 0) {
-               printaddr(addr);
-               goto out;
-       }
-       tprintf("%02x", buf[0]);
-       for (i = 1; i < allocated; ++i)
-               tprintf(", %02x", buf[i]);
-       if (allocated != len)
-               tprints(", ...");
-out:
-       free(buf);
-       tprints("]");
+       unsigned char buf;
+
+       print_array(tcp, addr, len, &buf, sizeof(buf),
+                   umoven_or_printaddr, print_uchar, 0);
 }
 
 static int