Blame


1 b2cfc4e2 2003-09-30 devnull /*
2 b2cfc4e2 2003-09-30 devnull * We assume there's only one error buffer for the whole system.
3 b2cfc4e2 2003-09-30 devnull * If you use ffork, you need to provide a _syserrstr. Since most
4 b2cfc4e2 2003-09-30 devnull * people will use libthread (which provides a _syserrstr), this is
5 b2cfc4e2 2003-09-30 devnull * okay.
6 b2cfc4e2 2003-09-30 devnull */
7 b2cfc4e2 2003-09-30 devnull
8 8ad51794 2004-03-25 devnull #include <u.h>
9 b2cfc4e2 2003-09-30 devnull #include <errno.h>
10 b2cfc4e2 2003-09-30 devnull #include <string.h>
11 8ad51794 2004-03-25 devnull #include <libc.h>
12 b2cfc4e2 2003-09-30 devnull
13 b2cfc4e2 2003-09-30 devnull enum
14 b2cfc4e2 2003-09-30 devnull {
15 b2cfc4e2 2003-09-30 devnull EPLAN9 = 0x19283745,
16 b2cfc4e2 2003-09-30 devnull };
17 b2cfc4e2 2003-09-30 devnull
18 b2cfc4e2 2003-09-30 devnull char *(*_syserrstr)(void);
19 b2cfc4e2 2003-09-30 devnull static char xsyserr[ERRMAX];
20 b2cfc4e2 2003-09-30 devnull static char*
21 b2cfc4e2 2003-09-30 devnull getsyserr(void)
22 b2cfc4e2 2003-09-30 devnull {
23 b2cfc4e2 2003-09-30 devnull char *s;
24 b2cfc4e2 2003-09-30 devnull
25 b2cfc4e2 2003-09-30 devnull s = nil;
26 b2cfc4e2 2003-09-30 devnull if(_syserrstr)
27 b2cfc4e2 2003-09-30 devnull s = (*_syserrstr)();
28 b2cfc4e2 2003-09-30 devnull if(s == nil)
29 b2cfc4e2 2003-09-30 devnull s = xsyserr;
30 b2cfc4e2 2003-09-30 devnull return s;
31 b2cfc4e2 2003-09-30 devnull }
32 b2cfc4e2 2003-09-30 devnull
33 b2cfc4e2 2003-09-30 devnull int
34 b2cfc4e2 2003-09-30 devnull errstr(char *err, uint n)
35 b2cfc4e2 2003-09-30 devnull {
36 b2cfc4e2 2003-09-30 devnull char tmp[ERRMAX];
37 b2cfc4e2 2003-09-30 devnull char *syserr;
38 b2cfc4e2 2003-09-30 devnull
39 b2cfc4e2 2003-09-30 devnull syserr = getsyserr();
40 b2cfc4e2 2003-09-30 devnull if(errno != EPLAN9)
41 b2cfc4e2 2003-09-30 devnull strcpy(syserr, strerror(errno));
42 b2cfc4e2 2003-09-30 devnull
43 b2cfc4e2 2003-09-30 devnull strecpy(tmp, tmp+ERRMAX, syserr);
44 b2cfc4e2 2003-09-30 devnull strecpy(syserr, syserr+ERRMAX, err);
45 b2cfc4e2 2003-09-30 devnull strecpy(err, err+n, tmp);
46 b2cfc4e2 2003-09-30 devnull errno = EPLAN9;
47 b2cfc4e2 2003-09-30 devnull return 0;
48 b2cfc4e2 2003-09-30 devnull }
49 b2cfc4e2 2003-09-30 devnull
50 b2cfc4e2 2003-09-30 devnull void
51 b2cfc4e2 2003-09-30 devnull rerrstr(char *err, uint n)
52 b2cfc4e2 2003-09-30 devnull {
53 b2cfc4e2 2003-09-30 devnull char *syserr;
54 b2cfc4e2 2003-09-30 devnull
55 b2cfc4e2 2003-09-30 devnull syserr = getsyserr();
56 b2cfc4e2 2003-09-30 devnull if(errno != EPLAN9)
57 b2cfc4e2 2003-09-30 devnull strcpy(syserr, strerror(errno));
58 b2cfc4e2 2003-09-30 devnull strecpy(err, err+n, syserr);
59 b2cfc4e2 2003-09-30 devnull }
60 b2cfc4e2 2003-09-30 devnull
61 b2cfc4e2 2003-09-30 devnull /* replaces __errfmt in libfmt */
62 b2cfc4e2 2003-09-30 devnull
63 b2cfc4e2 2003-09-30 devnull int
64 b2cfc4e2 2003-09-30 devnull __errfmt(Fmt *f)
65 b2cfc4e2 2003-09-30 devnull {
66 b2cfc4e2 2003-09-30 devnull if(errno == EPLAN9)
67 b2cfc4e2 2003-09-30 devnull return fmtstrcpy(f, getsyserr());
68 b2cfc4e2 2003-09-30 devnull return fmtstrcpy(f, strerror(errno));
69 b2cfc4e2 2003-09-30 devnull }
70 169aba14 2003-10-14 devnull
71 169aba14 2003-10-14 devnull void
72 169aba14 2003-10-14 devnull werrstr(char *fmt, ...)
73 169aba14 2003-10-14 devnull {
74 169aba14 2003-10-14 devnull va_list arg;
75 169aba14 2003-10-14 devnull char buf[ERRMAX];
76 169aba14 2003-10-14 devnull
77 169aba14 2003-10-14 devnull va_start(arg, fmt);
78 169aba14 2003-10-14 devnull vseprint(buf, buf+ERRMAX, fmt, arg);
79 169aba14 2003-10-14 devnull va_end(arg);
80 169aba14 2003-10-14 devnull errstr(buf, ERRMAX);
81 169aba14 2003-10-14 devnull }
82 fd04aace 2003-11-23 devnull
83 fd04aace 2003-11-23 devnull char*
84 fd04aace 2003-11-23 devnull gerrstr(void)
85 fd04aace 2003-11-23 devnull {
86 fd04aace 2003-11-23 devnull char *s;
87 fd04aace 2003-11-23 devnull
88 fd04aace 2003-11-23 devnull s = getsyserr();
89 fd04aace 2003-11-23 devnull if(errno != EPLAN9)
90 fd04aace 2003-11-23 devnull strcpy(s, strerror(errno));
91 fd04aace 2003-11-23 devnull return s;
92 fd04aace 2003-11-23 devnull }
93 fd04aace 2003-11-23 devnull
94 fd04aace 2003-11-23 devnull