#include <stdio.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#ifdef __STDC__
#  include <stdarg.h>
#  define VASTART  va_start(ap,fmt)
#  define VAALIST  ...
#else
#  include <varargs.h>
#  define VASTART  va_start(ap)
#  define VAALIST  va_alist
#endif

/*
 * log to the debug log file. 
 * flush the results immediately
 */
#ifdef	__STDC__
void debuglogfile(FILE *fp, char *fmt, ...)
#else
 void debuglogfile(fp, fmt, VAALIST )
FILE *fp;
char *fmt;
#endif
{
  char buf[2048];
  va_list ap;

  VASTART;
  vsprintf(buf, fmt, ap);
  va_end(ap);

  fprintf(fp, "%s", buf);
  fflush(fp);
}

#ifdef	__STDC__
int debuglog( char *fmt, ... )
#else
 int debuglog(fmt, VAALIST )
char *fmt;
#endif
{
  char buf[2048];
  va_list ap;

  VASTART;
  vsprintf(buf, fmt, ap);
  va_end(ap);

  debuglogfile(stderr, "%s", buf);
  return 0;
}

