#include <9pm/u.h>
#include <9pm/libc.h>
#include "dat.h"
#include "fns.h"

int
errstr(char *buf, uint nbuf)
{
	static char syserr[ERRMAX];
	char *err, tmp[ERRMAX];
	Proc *p;

	p = up;
	if(p)
		err = p->errstr;
	else
		err = syserr;

	buf[nbuf-1] = '\0';
	utfecpy(tmp, tmp+ERRMAX, err);
	utfecpy(err, err+ERRMAX, buf);
	utfecpy(buf, buf+nbuf, tmp);
	return 0;
}

void
oserror(void)
{
	char buf[ERRMAX];

	osrerrstr(buf, sizeof buf);
	errstr(buf, sizeof buf);
}
