static struct backtrace_state *btstate;
#endif
+#define KEEPSIZE 10000
+static char membuf[KEEPSIZE];
+static size_t memwidx = 0; /* write index */
+
/* LeakSantizier (LSAN) calls _exit() instead of exit() when a leak is detected
on exit so the logfile must be closed explicitly or data could be lost.
Though _exit() does not call atexit handlers such as this, LSAN's call to
if(curl_dbg_logfile &&
curl_dbg_logfile != stderr &&
curl_dbg_logfile != stdout) {
+ if(memwidx)
+ fwrite(membuf, 1, memwidx, curl_dbg_logfile);
/* !checksrc! disable BANNEDFUNC 1 */
fclose(curl_dbg_logfile);
}
void curl_dbg_log(const char *format, ...)
{
char buf[1024];
- int nchars;
+ size_t nchars;
va_list ap;
if(!curl_dbg_logfile)
if(nchars > (int)sizeof(buf) - 1)
nchars = (int)sizeof(buf) - 1;
- if(nchars > 0)
- fwrite(buf, 1, (size_t)nchars, curl_dbg_logfile);
+ if(nchars > 0) {
+ if(KEEPSIZE - nchars < memwidx) {
+ /* flush */
+ fwrite(membuf, 1, memwidx, curl_dbg_logfile);
+ fflush(curl_dbg_logfile);
+ memwidx = 0;
+ }
+ if(memwidx) {
+ /* the previous line ends with a newline */
+ DEBUGASSERT(membuf[memwidx - 1] == '\n');
+ }
+ memcpy(&membuf[memwidx], buf, nchars);
+ memwidx += nchars;
+ }
}
#endif /* CURLDEBUG */