const char *format, ...)
{
va_list args;
+ int retval;
va_start (args, format);
- vsnprintf (buffer, buf_size, format, args);
+ retval = vsnprintf (buffer, buf_size, format, args);
va_end (args);
+
+ return retval;
}
\f
/* printf() and friends internals. You do not need to understand
PLUS = 1 << 1,
SPACE = 1 << 2,
POUND = 1 << 3,
- ZERO = 1 << 4
+ ZERO = 1 << 4,
+ GROUP = 1 << 5
}
flags;
case '0':
c->flags |= ZERO;
break;
+ case '\'':
+ c->flags |= GROUP;
+ break;
default:
format--;
goto not_a_flag;
cp = buf;
while (value > 0)
{
+ if ((c->flags & GROUP) && cp > buf && (cp - buf) % 3 == 0)
+ *cp++ = ',';
*cp++ = digits[value % base];
value /= base;
}
}
}
}
+\f
+void
+hex_dump (const void *buffer, size_t size)
+{
+ const size_t n_per_line = 16;
+ const uint8_t *p = buffer;
+ size_t ofs = 0;
+
+ while (size > 0)
+ {
+ size_t n, i;
+
+ printk ("%08zx", ofs);
+ n = size >= n_per_line ? n_per_line : size;
+ for (i = 0; i < n; i++)
+ printk ("%c%02x", i == n / 2 ? '-' : ' ', (unsigned) p[i]);
+ for (; i < n_per_line; i++)
+ printk (" ");
+ printk (" |");
+ for (i = 0; i < n; i++)
+ printk ("%c", isprint (p[i]) ? p[i] : '.');
+ for (; i < n_per_line; i++)
+ printk (" ");
+ printk ("|\n");
+
+ p += n;
+ ofs += n;
+ size -= n;
+ }
+}