-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhexdump.hh
More file actions
37 lines (29 loc) · 1.3 KB
/
hexdump.hh
File metadata and controls
37 lines (29 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef CS61_HEXDUMP_HH
#define CS61_HEXDUMP_HH
#include <cstdio>
#include <cassert>
#include <cstdlib>
// hexdump(ptr, size)
// Print a hexdump of the `size` bytes of data starting at `ptr`
// to the standard output. The hexdump format is:
// XXXXXXXX BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB BB |CCCCCCCCCCCCCCCC|
// where XXXXXXXX is the address of the first byte in the line,
// the BBs are hexadecimal values of those bytes, and the Cs show
// the printable ASCII characters corresponding to those bytes
// (`.` is displayed for non-printable characters).
void hexdump(const void* ptr, size_t size);
// hexdump_object(object)
// Like hexdump(&object, sizeof(object)).
#define hexdump_object(object) hexdump(&(object), sizeof((object)))
// fhexdump(f, ptr, size)
// Like `hexdump(ptr, size)`, but print to file `f` rather than standard
// output.
void fhexdump(FILE* f, const void* ptr, size_t size);
// fhexdump_object(f, object)
// Like `fhexdump(f, &object, sizeof(object))`.
#define fhexdump_object(f, object) fhexdump((f), &(object), sizeof((object)))
// fhexdump_at(f, first_offset, ptr, size)
// Like fhexdump, but start with offset `first_offset` instead of the
// address of `ptr`.
void fhexdump_at(FILE* f, size_t first_offset, const void* ptr, size_t size);
#endif