Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

print_utils.h 850B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef STRACE_PRINT_UTILS_H
  2. # define STRACE_PRINT_UTILS_H
  3. # include <inttypes.h>
  4. /* Hexadecimal output utils */
  5. static const char hex_chars[16] = "0123456789abcdef";
  6. /**
  7. * Character array representing hexadecimal encoding of a character value.
  8. *
  9. * @param b_ Byte to provide representation for.
  10. */
  11. # define BYTE_HEX_CHARS(b_) \
  12. hex_chars[((uint8_t) (b_)) >> 4], hex_chars[((uint8_t) (b_)) & 0xf]
  13. # define BYTE_HEX_CHARS_PRINTF(b_) \
  14. '\\', 'x', BYTE_HEX_CHARS(b_)
  15. # define BYTE_HEX_CHARS_PRINTF_QUOTED(b_) \
  16. '\'', BYTE_HEX_CHARS_PRINTF(b_), '\''
  17. static inline char *
  18. sprint_byte_hex(char *buf, uint8_t val)
  19. {
  20. *buf++ = hex_chars[val >> 4];
  21. *buf++ = hex_chars[val & 0xf];
  22. return buf;
  23. }
  24. /* Character classification utils */
  25. static inline bool
  26. is_print(uint8_t c)
  27. {
  28. return (c >= ' ') && (c < 0x7f);
  29. }
  30. #endif /* STRACE_PRINT_UTILS_H */