#include "config.h"
#include "debug.h"
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#define DEBUG_BUF_SIZE ((256+20)*3+10)
static char DebugBuffer[DEBUG_BUF_SIZE];
#define LOG_TO_STDERR
void log_msg(const int priority, const char *fmt, ...)
{
va_list argptr;
va_start(argptr, fmt);
(void)vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
va_end(argptr);
#ifdef LOG_TO_STDERR
(void)fprintf(stderr, "%s\n", DebugBuffer);
#endif
}
void log_xxd(const int priority, const char *msg, const unsigned char *buffer,
const int len)
{
int i;
char *c, *debug_buf_end;
debug_buf_end = DebugBuffer + DEBUG_BUF_SIZE - 5;
strncpy(DebugBuffer, msg, sizeof(DebugBuffer)-1);
c = DebugBuffer + strlen(DebugBuffer);
for (i = 0; (i < len) && (c < debug_buf_end); ++i)
{
(void)sprintf(c, "%02X ", (unsigned char)buffer[i]);
c += strlen(c);
}
#ifdef LOG_TO_STDERR
if (c >= debug_buf_end)
(void)fprintf(stderr, "Debug buffer too short\n");
(void)fprintf(stderr, "%s\n", DebugBuffer);
#endif
}