Fix indentation; printout length
pthread_mutex_t dbg_mutex;
void dbg_fprint_bytes(FILE* out_file, void* bytes, int byte_count) {
- for (int i = 0; i < byte_count; ++i) {
+ int reasonable_upper_limit = 160;
+ if (byte_count <= 0) return;
+
+ if (byte_count > reasonable_upper_limit) {
+ fprintf(out_file, "(%d bytes, showing first %d) ", byte_count, reasonable_upper_limit);
+ }
+
+ for (int i = 0; i < (byte_count <= reasonable_upper_limit ? byte_count : reasonable_upper_limit); ++i) {
fprintf(out_file, i%2 == 0 ? "%02x" : "%02x ", ((uint8_t*)bytes)[i]);
}
+
+ if (byte_count > reasonable_upper_limit) {
+ fprintf(out_file, "...");
+ }
}
#endif
