/*
**	$VER: debuglib.c 1.0 (30.09.94)
**
**	debug.library functions
**
**	© Copyright 1994 by Norbert Püschel
**	All Rights Reserved
*/

#include <proto/exec.h>
#include <proto/dos.h>

#include <dos/dostags.h>

#include <string.h>

struct DosLibrary *DOSBase;

struct SignalSemaphore S;

BOOL __saveds LibInit(void)

{
  DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37);
  if(DOSBase) {
    memset(&S,0,sizeof(struct SignalSemaphore));
    InitSemaphore(&S);
    return(TRUE);
  }
  return(FALSE);
}

BOOL __saveds LibExpunge(void)

{
  CloseLibrary((struct Library *)DOSBase);
  return(TRUE);
}

void __saveds __asm LIBDEBUGA(register __d1 STRPTR fname,
                              register __d2 STRPTR format,
                              register __d3 LONG *args)

{
  BPTR file;

  ObtainSemaphore(&S);

  file = Open(fname,MODE_READWRITE);
  if(file) {
    Seek(file,0,OFFSET_END);
    VFPrintf(file,format,args);
    Close(file);
  }

  ReleaseSemaphore(&S);
}
