1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#include "a.h"
enum
{
EPLAN9 = 0x19283745 /* see /usr/local/plan9/src/lib9/errstr.c */
};
typedef struct Error Error;
struct Error
{
char *text;
int err;
int len;
};
static Error errortab[] = {
{ "permitted", EPERM },
{ "permission", EACCES },
{ "access", EACCES },
{ "exists", EEXIST },
{ "exist", ENOENT },
{ "no such", ENOENT },
{ "not found", ENOENT },
{ "input/output", EIO },
{ "timeout", ETIMEDOUT },
{ "timed out", ETIMEDOUT },
{ "i/o", EIO },
{ "too long", E2BIG },
{ "interrupt", EINTR },
{ "no such", ENODEV },
{ "bad file", EBADF },
{ " fid ", EBADF },
{ "temporar", EAGAIN },
{ "memory", ENOMEM },
{ "is a directory", EISDIR },
{ "directory", ENOTDIR },
{ "argument", EINVAL },
{ "pipe", EPIPE },
{ "in use", EBUSY },
{ "busy", EBUSY },
{ "illegal", EINVAL },
{ "invalid", EINVAL },
{ "read-only", EROFS },
{ "read only", EROFS },
#ifdef EPROTO
{ "proto", EPROTO },
#else
{ "proto", EINVAL },
#endif
{ "entry", ENOENT },
};
int
errstr2errno(void)
{
char e[ERRMAX];
int i, len;
if(errno != EPLAN9)
return errno;
if(errortab[0].len == 0)
for(i=0; i<nelem(errortab); i++)
errortab[i].len = strlen(errortab[i].text);
rerrstr(e, sizeof e);
len = strlen(e);
for(i=0; i<nelem(errortab); i++)
if(errortab[i].len <= len && cistrstr(e, errortab[i].text))
return errortab[i].err;
return ERANGE; /* who knows - be blatantly wrong */
}
|