return !memcmp(str, pfx, strlen(pfx));
}
-void print_hex(void *arg, unsigned int n, const char *sep)
+void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep)
{
unsigned char *data = arg;
unsigned int i;
if (!i)
/* nothing */;
else if (!(i % 16))
- printf("\n");
+ fprintf(f, "\n");
else if (!(i % 8))
- printf(" ");
+ fprintf(f, " ");
else
pfx = sep;
- printf("%s%02hhx", i ? pfx : "", data[i]);
+ fprintf(f, "%s%02hhx", i ? pfx : "", data[i]);
}
}
!break_names;
printf("key:%c", break_names ? '\n' : ' ');
- print_hex(key, info->key_size, " ");
+ fprint_hex(stdout, key, info->key_size, " ");
printf(single_line ? " " : "\n");
printf("value:%c", break_names ? '\n' : ' ');
- print_hex(value, info->value_size, " ");
+ fprint_hex(stdout, value, info->value_size, " ");
printf("\n");
} else {
n = get_possible_cpus();
printf("key:\n");
- print_hex(key, info->key_size, " ");
+ fprint_hex(stdout, key, info->key_size, " ");
printf("\n");
for (i = 0; i < n; i++) {
printf("value (CPU %02d):%c",
i, info->value_size > 16 ? '\n' : ' ');
- print_hex(value + i * info->value_size,
- info->value_size, " ");
+ fprint_hex(stdout, value + i * info->value_size,
+ info->value_size, " ");
printf("\n");
}
}
print_entry(&info, key, value);
} else {
info("can't lookup element with key: ");
- print_hex(key, info.key_size, " ");
- printf("\n");
+ fprint_hex(stderr, key, info.key_size, " ");
+ fprintf(stderr, "\n");
}
prev_key = key;
print_entry(&info, key, value);
} else if (errno == ENOENT) {
printf("key:\n");
- print_hex(key, info.key_size, " ");
+ fprint_hex(stdout, key, info.key_size, " ");
printf("\n\nNot found\n");
} else {
err("lookup failed: %s\n", strerror(errno));
if (key) {
printf("key:\n");
- print_hex(key, info.key_size, " ");
+ fprint_hex(stdout, key, info.key_size, " ");
printf("\n");
} else {
printf("key: None\n");
}
printf("next key:\n");
- print_hex(nextkey, info.key_size, " ");
+ fprint_hex(stdout, nextkey, info.key_size, " ");
printf("\n");
exit_free: