MCPcopy Index your code
hub / github.com/F-Stack/f-stack / hexdump

Function hexdump

tools/libutil/hexdump.c:46–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44#include <stdio.h>
45
46void
47hexdump(const void *ptr, int length, const char *hdr, int flags)
48{
49 int i, j, k;
50 int cols;
51 const unsigned char *cp;
52 char delim;
53
54 if ((flags & HD_DELIM_MASK) != 0)
55 delim = (flags & HD_DELIM_MASK) >> 8;
56 else
57 delim = ' ';
58
59 if ((flags & HD_COLUMN_MASK) != 0)
60 cols = flags & HD_COLUMN_MASK;
61 else
62 cols = 16;
63
64 cp = ptr;
65 for (i = 0; i < length; i+= cols) {
66 if (hdr != NULL)
67 printf("%s", hdr);
68
69 if ((flags & HD_OMIT_COUNT) == 0)
70 printf("%04x ", i);
71
72 if ((flags & HD_OMIT_HEX) == 0) {
73 for (j = 0; j < cols; j++) {
74 k = i + j;
75 if (k < length)
76 printf("%c%02x", delim, cp[k]);
77 else
78 printf(" ");
79 }
80 }
81
82 if ((flags & HD_OMIT_CHARS) == 0) {
83 printf(" |");
84 for (j = 0; j < cols; j++) {
85 k = i + j;
86 if (k >= length)
87 printf(" ");
88 else if (cp[k] >= ' ' && cp[k] <= '~')
89 printf("%c", cp[k]);
90 else
91 printf(".");
92 }
93 printf("|");
94 }
95 printf("\n");
96 }
97}
98

Callers 1

sfp_statusFunction · 0.50

Calls 1

printfFunction · 0.50

Tested by

no test coverage detected