#include #include #include #include #include "debug.h" static FILE *g_dfile; void debug_init(void) { const char *home = getenv("HOME"); if (!home) home = "/tmp"; const char *suffix = "/Desktop/debugf.txt"; char *fname = malloc(strlen(home) + strlen(suffix) + 1); if (!fname) return; // okay, fine, no debug file g_dfile = fopen(fname, "a"); if (!g_dfile) { g_dfile = NULL; return; // fine! } // Disable buffering setvbuf(g_dfile, NULL, _IONBF, 0); fprintf(g_dfile, "--------\n"); } void debug_deinit(void) { if (g_dfile) fclose(g_dfile); } __attribute__((format (printf, 1, 2))) void debugf(const char *restrict format, ...) { if (!g_dfile) return; va_list ap; va_start(ap, format); vfprintf(g_dfile, format, ap); va_end(ap); }