kbd: use a better get_key method
[thunix.git] / kernel / hexdump.c
blob765331858ce53d2e80996aeb9bf339fd286af746
1 /*
2 * The hex dump lib.
4 * Copyright (C) 2009 Liu Aleaxander -- All rights reserved. This file
5 * may be redistributed under the terms of the GNU Public License.
6 */
8 #include <stdio.h>
9 #include <string.h>
11 void hexdump(void *data, int len)
13 int i = 0;
14 int index = 0;
15 unsigned int base = 0;
16 unsigned char *p = data;
17 unsigned char hex[16 * 3 + 1] = {0, };
18 unsigned char text[16 + 1] = {0, };
19 unsigned char c;
21 for (i = 0; i < len; i++) {
22 index = i & 0xf;
23 if (i && index == 0) {
24 /* print the buffer before reset it */
25 printk("%08x %-48s |%-16s|\n", base, hex, text);
26 base += 0x10;
27 memset(hex, 0, sizeof hex);
28 memset(text, 0, sizeof text);
31 c = *p++;
32 sprintk((char *)&hex[index * 3], "%02x ", c);
33 if (c < 0x20 || c > 0x7f)
34 text[index] = '.';
35 else
36 text[index] = c;
39 /* print the last part */
40 printk("%08x %-48s |%-16s|\n", base, hex, text);