plan9port/src/cmd/9pfuse/errstr.c

75 lines
1.4 KiB
C
Raw Normal View History

2006-07-23 03:33:00 +00:00
#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[] = {
2006-07-23 05:03:46 +00:00
{ "permitted", EPERM },
{ "permission", EACCES },
{ "access", EACCES },
{ "exists", EEXIST },
{ "exist", ENOENT },
{ "no such", ENOENT },
{ "not found", ENOENT },
2020-01-15 10:57:41 +03:00
{ "not implemented", ENOSYS},
2006-07-23 05:03:46 +00:00
{ "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 },
2008-07-24 07:59:25 -07:00
{ "invalid", EINVAL },
2006-07-23 05:03:46 +00:00
{ "read-only", EROFS },
{ "read only", EROFS },
2020-01-15 10:57:41 +03:00
{ "stale ", ESTALE},
#ifdef EPROTO
2006-07-23 05:03:46 +00:00
{ "proto", EPROTO },
#else
{ "proto", EINVAL },
#endif
2006-07-23 05:03:46 +00:00
{ "entry", ENOENT },
2006-07-23 03:33:00 +00:00
};
int
errstr2errno(void)
{
char e[ERRMAX];
int i, len;
2006-07-23 03:33:00 +00:00
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;
2006-07-23 05:03:46 +00:00
return ERANGE; /* who knows - be blatantly wrong */
2006-07-23 03:33:00 +00:00
}