blob: cc424302bed82ece3c96d3e74f4831371b386c7e [file] [log] [blame] [edit]
#include "hex.h"
#include <stdio.h>
hexdmp_error_t stderr_hexdmp(const char * description, const unsigned char * data_ptr, size_t datasz){
if(description) {
fprintf(stderr,"%s:\n", description);
}
if(datasz == 0) {
fprintf(stderr,"No Data, Size is 0");
return HEXDMP_OK;
}
if(!data_ptr) {
fprintf(stderr,"No data pointer");
return HEXDMP_ERROR;
}
for(size_t i = 0; i < datasz; i += 16) {
// First print the offset.
fprintf(stderr, "%08x", (unsigned) i);
// Now print the next (at most) 16 characters.
for(size_t j = 0; (j < 16) && (i+j) < datasz; j++) {
fprintf(stderr, " %02x", data_ptr[i+j]);
}
// Print a newline.
fprintf(stderr, "\n");
}
return HEXDMP_OK;
}