+#ifdef DEBUG
+#define debug(...) fprintf(stderr, __VA_ARGS__)
+static void debug_dump_buffer(const char *filename, uint8_t *buffer, unsigned int len)
+{
+ FILE *dump_file;
+
+ dump_file = fopen(filename, "wb");
+ if (dump_file == NULL) {
+ fprintf(stderr, "Failed to open %s: %s\n", filename, strerror(errno));
+ return;
+ }
+
+ fwrite(buffer, 1, len, dump_file);
+ fclose(dump_file);
+}
+#else
+#define debug(...) do {} while(0)
+static void debug_dump_buffer(const char *filename, uint8_t *buffer, unsigned int len)
+{
+ (void)filename;
+ (void)buffer;
+ (void)len;
+}
+#endif
+