2003-09-30 17:47:41 +00:00
|
|
|
/*
|
|
|
|
* We assume there's only one error buffer for the whole system.
|
|
|
|
* If you use ffork, you need to provide a _syserrstr. Since most
|
|
|
|
* people will use libthread (which provides a _syserrstr), this is
|
|
|
|
* okay.
|
|
|
|
*/
|
|
|
|
|
2004-03-25 23:03:57 +00:00
|
|
|
#include <u.h>
|
2003-09-30 17:47:41 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2004-03-25 23:03:57 +00:00
|
|
|
#include <libc.h>
|
2003-09-30 17:47:41 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
EPLAN9 = 0x19283745,
|
|
|
|
};
|
|
|
|
|
|
|
|
char *(*_syserrstr)(void);
|
|
|
|
static char xsyserr[ERRMAX];
|
|
|
|
static char*
|
|
|
|
getsyserr(void)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = nil;
|
|
|
|
if(_syserrstr)
|
|
|
|
s = (*_syserrstr)();
|
|
|
|
if(s == nil)
|
|
|
|
s = xsyserr;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
errstr(char *err, uint n)
|
|
|
|
{
|
|
|
|
char tmp[ERRMAX];
|
|
|
|
char *syserr;
|
|
|
|
|
2005-01-04 22:18:54 +00:00
|
|
|
strecpy(tmp, tmp+ERRMAX, err);
|
|
|
|
rerrstr(err, n);
|
2003-09-30 17:47:41 +00:00
|
|
|
syserr = getsyserr();
|
2005-01-04 22:18:54 +00:00
|
|
|
strecpy(syserr, syserr+ERRMAX, tmp);
|
2003-09-30 17:47:41 +00:00
|
|
|
errno = EPLAN9;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rerrstr(char *err, uint n)
|
|
|
|
{
|
|
|
|
char *syserr;
|
|
|
|
|
|
|
|
syserr = getsyserr();
|
2005-01-04 22:18:54 +00:00
|
|
|
if(errno == EINTR)
|
|
|
|
strcpy(syserr, "interrupted");
|
|
|
|
else if(errno != EPLAN9)
|
2003-09-30 17:47:41 +00:00
|
|
|
strcpy(syserr, strerror(errno));
|
|
|
|
strecpy(err, err+n, syserr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* replaces __errfmt in libfmt */
|
|
|
|
|
|
|
|
int
|
|
|
|
__errfmt(Fmt *f)
|
|
|
|
{
|
|
|
|
if(errno == EPLAN9)
|
|
|
|
return fmtstrcpy(f, getsyserr());
|
|
|
|
return fmtstrcpy(f, strerror(errno));
|
|
|
|
}
|
2003-10-14 02:10:47 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
werrstr(char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list arg;
|
|
|
|
char buf[ERRMAX];
|
|
|
|
|
|
|
|
va_start(arg, fmt);
|
|
|
|
vseprint(buf, buf+ERRMAX, fmt, arg);
|
|
|
|
va_end(arg);
|
|
|
|
errstr(buf, ERRMAX);
|
|
|
|
}
|
2003-11-23 18:12:54 +00:00
|
|
|
|