+static void write_log(char *buf, int len, char *fmt, ...)
+{
+ va_list ap;
+ int i;
+
+ if ((!logfile) && (!verbose))
+ return;
+
+ if (logfile)
+ print_timestamp(logfile);
+ if (verbose)
+ print_timestamp(stdout);
+
+ if (fmt) {
+ if (logfile) {
+ va_start(ap, fmt);
+ vfprintf(logfile, fmt, ap);
+ va_end(ap);
+ }
+ if (verbose) {
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ }
+ }
+
+ if (buf && len) {
+ for (i = 0; i < len; i++) {
+ if (logfile)
+ fprintf(logfile, "%c", buf[i]);
+ if (verbose)
+ printf("%c", buf[i]);
+ }
+ if (logfile)
+ fprintf(logfile, "\n");
+ if (verbose)
+ printf("\n");
+ }
+ if (logfile)
+ fflush(logfile);
+}
+