* src/output.h (output_write): Remove unused function declaration * src/makeint.h (dbg): Add formatting attribute * src/misc.c (dbg): Keep the file open, once opened
diff --git a/src/makeint.h b/src/makeint.h index 8a8eab3..f88e3fd 100644 --- a/src/makeint.h +++ b/src/makeint.h
@@ -668,7 +668,7 @@ # define SPIN(_s) spin (_s) void spin (const char* suffix); # define DBG(_f) dbg _f -void dbg (const char *fmt, ...); +void dbg (const char *fmt, ...) ATTRIBUTE ((__format__ (__printf__, 1, 2))); #else # define SPIN(_s) /* Never put this code into Git or a release. */
diff --git a/src/misc.c b/src/misc.c index a6633fa..2352d6d 100644 --- a/src/misc.c +++ b/src/misc.c
@@ -613,7 +613,6 @@ void dbg (const char *fmt, ...) { - FILE *fp = fopen ("/tmp/gmkdebug.log", "a+"); va_list args; char buf[4096]; @@ -621,9 +620,13 @@ vsprintf (buf, fmt, args); va_end (args); - fprintf(fp, "%u: %s\n", (unsigned) make_pid (), buf); - fflush (fp); - fclose (fp); + { + static FILE *fp = NULL; + if (!fp) + fp = fopen ("/tmp/gmkdebug.log", "a+"); + fprintf (fp, "%u: %s\n", (unsigned) make_pid (), buf); + fflush (fp); + } } #endif
diff --git a/src/output.h b/src/output.h index a6c714b..f643113 100644 --- a/src/output.h +++ b/src/output.h
@@ -34,10 +34,6 @@ #define OUTPUT_TRACED() do{ stdio_traced = 1; }while(0) #define OUTPUT_IS_TRACED() (!!stdio_traced) -/* Write a buffer directly to the given file descriptor. - This handles errors etc. */ -int output_write (int fd, const void *buffer, size_t len); - /* Initialize and close a child output structure: if NULL do this program's output (this should only be done once). */ void output_init (struct output *out);