code: mafs

ref: cfb63eceee23064149992ca27a04c9679d4c2cf0
dir: /error.c/

View raw version
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"

s8 envpidx = -1;		/* the index in _privates holding the Errenv location. hack: hoping that this will be the same across all processes */
Errenv **envpp = nil;

int
waserror(void)
{
	Errenv *env = _privates[envpidx];
	++env->nlabel;
	return setjmp(env->label[env->nlabel-1]);
}

void
poperror(void)
{
	Errenv *env = *envpp;
	--env->nlabel;
}

void
nexterror(void)
{
	Errenv *env = _privates[envpidx];
	longjmp(env->label[--env->nlabel], 1);
}

void
error(s8 *fmt, ...)
{
	va_list arg;
	char buf[ERRMAX];

	va_start(arg, fmt);
	vseprint(buf, buf+ERRMAX, fmt, arg);
	va_end(arg);
	errstr(buf, ERRMAX);
	nexterror();
}