static ssize_t read_buildid(void *va, long n, off64_t off) { /* Each build_id byte needs 2 chars, and 1 for the \0 */ char build_id[BUILD_ID_SZ * 2 + 1] = {0}; uint8_t hi, lo; uint8_t *b = (uint8_t*)get_build_id_start(); for (int i = 0; i < BUILD_ID_SZ; i++) { hi = *b >> 4; lo = *b & 0xf; build_id[i * 2 + 0] = num_to_nibble(hi); build_id[i * 2 + 1] = num_to_nibble(lo); b++; } return readmem(off, va, n, build_id, sizeof(build_id)); }
int printf_hexdump(FILE *stream, const struct printf_info *info, const void *const *args) { uint8_t *arg = *(uint8_t**)args[0]; char *buf, *p; int ret; /* 3 chars per byte, one for the space */ buf = malloc(3 * info->prec); p = buf; for (int i = 0; i < info->prec; i++) { if (i) *p++ = ' '; *p++ = num_to_nibble(*arg >> 4); *p++ = num_to_nibble(*arg); arg++; } ret = fwrite(buf, 1, p - buf, stream); free(buf); return ret; }