]> granicus.if.org Git - strace/blob - print_utils.h
bfin, csky, m68k, sh: fix build regression
[strace] / print_utils.h
1 #ifndef STRACE_PRINT_UTILS_H
2 # define STRACE_PRINT_UTILS_H
3
4 # include <inttypes.h>
5
6 /* Hexadecimal output utils */
7
8 static const char hex_chars[16] = "0123456789abcdef";
9
10 /**
11  * Character array representing hexadecimal encoding of a character value.
12  *
13  * @param b_ Byte to provide representation for.
14  */
15 # define BYTE_HEX_CHARS(b_) \
16         hex_chars[((uint8_t) (b_)) >> 4], hex_chars[((uint8_t) (b_)) & 0xf]
17 # define BYTE_HEX_CHARS_PRINTF(b_) \
18         '\\', 'x', BYTE_HEX_CHARS(b_)
19 # define BYTE_HEX_CHARS_PRINTF_QUOTED(b_) \
20         '\'', BYTE_HEX_CHARS_PRINTF(b_), '\''
21
22 static inline char *
23 sprint_byte_hex(char *buf, uint8_t val)
24 {
25         *buf++ = hex_chars[val >> 4];
26         *buf++ = hex_chars[val & 0xf];
27
28         return buf;
29 }
30
31 /* Character classification utils */
32
33 static inline bool
34 is_print(uint8_t c)
35 {
36         return (c >= ' ') && (c < 0x7f);
37 }
38
39 #endif /* STRACE_PRINT_UTILS_H */