#include <9pm/u.h>
#include <9pm/libc.h>
#include <9pm/ns.h>

void
nexterror(void)
{
	Proc *p;

	p = getproc();
	if(p->nerrjmp > nelem(p->errjmp))
		pm_panic("error stack overflow");	/* better late than never */
	if(p->nerrjmp == 0)
		pm_panic("error stack underflow");
	longjmp(p->errjmp[--p->nerrjmp], 1);
}

void
poperror(void)
{
	Proc *p;

	p = getproc();
	if(p->nerrjmp > nelem(p->errjmp))
		pm_panic("error stack overflow");	/* better late than never */
	if(p->nerrjmp == 0)
		pm_panic("error stack underflow");
	p->nerrjmp--;
}

void
error(char *s)
{
	Proc *p;

	p = getproc();
	utfecpy(p->err, p->err+ERRMAX, s);
	nexterror();
}

void
checkerrstack(void)
{
	Proc *p;

	p = getproc();
	if(p->nerrjmp)
		pm_panic("error stack leftovers");
}
