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: #include <basic.h>
52: #include <string.h>
53: #include <errno.h>
54: #include <tk/errno.h>
55:
56: LOCAL const struct {
57: int mer;
58: const char *msg;
59: } e_tbl[] = {
60: {MERCD(E_OK), "E_OK: Completed successfully"},
61: {MERCD(E_SYS), "E_SYS: System error"},
62: {MERCD(E_NOCOP), "E_NOCOP: Coprocessor disable"},
63: {MERCD(E_NOSPT), "E_NOSPT: Unsupported function"},
64: {MERCD(E_RSFN), "E_RSFN: Reserved function code number"},
65: {MERCD(E_RSATR), "E_RSATR: Reserved attribute"},
66: {MERCD(E_PAR), "E_PAR: Parameter error"},
67: {MERCD(E_ID), "E_ID: Incorrect ID number"},
68: {MERCD(E_CTX), "E_CTX: Context error"},
69: {MERCD(E_MACV), "E_MACV: Inaccessible memory/access violation"},
70: {MERCD(E_OACV), "E_OACV: Object access violation"},
71: {MERCD(E_ILUSE), "E_ILUSE: Incorrect system call use"},
72: {MERCD(E_NOMEM), "E_NOMEM: Insufficient memory"},
73: {MERCD(E_LIMIT), "E_LIMIT: Exceed system limits"},
74: {MERCD(E_OBJ), "E_OBJ: Incorrect object state"},
75: {MERCD(E_NOEXS), "E_NOEXS: Object does not exist"},
76: {MERCD(E_QOVR), "E_QOVR: Queuing overflow"},
77: {MERCD(E_RLWAI), "E_RLWAI: Forcibly release wait state"},
78: {MERCD(E_TMOUT), "E_TMOUT: Polling fail/time out"},
79: {MERCD(E_DLT), "E_DLT: Waited object was deleted"},
80: {MERCD(E_DISWAI), "E_DISWAI: Release wait caused by wait disable"},
81: {MERCD(E_IO), "E_IO: Output/input error"},
82: {MERCD(E_NOMDA), "E_NOMDA: No media"},
83: {MERCD(E_BUSY), "E_BUSY: Busy state"},
84: {MERCD(E_ABORT), "E_ABORT: Aborted"},
85: {MERCD(E_RONLY), "E_RONLY: Write protected"},
86: };
87:
88: LOCAL const struct {
89: int ser;
90: const char *msg;
91: } ex_tbl[] = {
92: {EPERM, "EX_PERM: Operation not permitted"},
93: {ENOENT, "EX_NOENT: No such file or directory"},
94: {ESRCH, "EX_SRCH: No such process"},
95: {EINTR, "EX_INTR: Interrupted system call"},
96: {EIO, "EX_IO: Input/output error"},
97: {ENXIO, "EX_NXIO: Device not configured"},
98: {E2BIG, "EX_2BIG: Argument list too long"},
99: {ENOEXEC, "EX_NOEXEC: Exec format error"},
100: {EBADF, "EX_BADF: Bad file descriptor"},
101: {ECHILD, "EX_CHILD: No child processes"},
102: {EDEADLK, "EX_DEADLK: Resource deadlock avoided"},
103: {ENOMEM, "EX_NOMEM: Cannot allocate memory"},
104: {EACCES, "EX_ACCES: Permission denied"},
105: {EFAULT, "EX_FAULT: Bad address"},
106: {EBUSY, "EX_BUSY: Device busy"},
107: {EEXIST, "EX_EXIST: File exists"},
108: {EXDEV, "EX_XDEV: Cross-device link"},
109: {ENODEV, "EX_NODEV: Operation not supported by device"},
110: {ENOTDIR, "EX_NOTDIR: Not a directory"},
111: {EISDIR, "EX_ISDIR: Is a directory"},
112: {EINVAL, "EX_INVAL: Invalid argument"},
113: {ENFILE, "EX_NFILE: Too many open files in system"},
114: {EMFILE, "EX_MFILE: Too many open files"},
115: {ENOTTY, "EX_NOTTY: Inappropriate ioctl for device"},
116: {EFBIG, "EX_FBIG: File too large"},
117: {ENOSPC, "EX_NOSPC: No space left on device"},
118: {ESPIPE, "EX_SPIPE: Illegal seek"},
119: {EROFS, "EX_ROFS: Read-only file system"},
120: {EMLINK, "EX_MLINK: Too many links"},
121: {EPIPE, "EX_PIPE: Broken pipe"},
122: {EDOM, "EX_DOM: Numerical argument out of domain"},
123: {ERANGE, "EX_RANGE: Result too large"},
124: {EAGAIN, "EX_AGAIN: Resource temporarily unavailable"},
125: {EINPROGRESS, "EX_INPROGRESS: Operation now in progress"},
126: {EALREADY, "EX_ALREADY: Operation already in progress"},
127: {ENOTSOCK, "EX_NOTSOCK: Socket operation on non-socket"},
128: {EDESTADDRREQ, "EX_DESTADDRREQ: Destination address required"},
129: {EMSGSIZE, "EX_MSGSIZE: Message too long"},
130: {EPROTOTYPE, "EX_PROTOTYPE: Protocol wrong type for socket"},
131: {ENOPROTOOPT, "EX_NOPROTOOPT: Protocol not available"},
132: {EPROTONOSUPPORT, "EX_PROTONOSUPPORT: Protocol not supported"},
133: {ESOCKTNOSUPPORT, "EX_SOCKTNOSUPPORT: Socket type not supported"},
134: {EOPNOTSUPP, "EX_OPNOTSUPP: Operation not supported"},
135: {EPFNOSUPPORT, "EX_PFNOSUPPORT: Protocol family not supported"},
136: {EADDRINUSE, "EX_ADDRINUSE: Address already in use"},
137: {EADDRNOTAVAIL, "EX_ADDRNOTAVAIL: Can't assign requested address"},
138: {ENETDOWN, "EX_NETDOWN: Network is down"},
139: {ENETUNREACH, "EX_NETUNREACH: Network is unreachable"},
140: {ENETRESET, "EX_NETRESET: Network dropped connection on reset"},
141: {ECONNABORTED, "EX_CONNABORTED: Software caused connection abort"},
142: {ECONNRESET, "EX_CONNRESET: Connection reset by peer"},
143: {ENOBUFS, "EX_NOBUFS: No buffer space available"},
144: {EISCONN, "EX_ISCONN: Socket is already connected"},
145: {ENOTCONN, "EX_NOTCONN: Socket is not connected"},
146: {ESHUTDOWN, "EX_SHUTDOWN: Can't send after socket shutdown"},
147: {ETIMEDOUT, "EX_TIMEDOUT: Operation timed out"},
148: {ECONNREFUSED, "EX_CONNREFUSED: Connection refused"},
149: {ELOOP, "EX_LOOP: Too many levels of symbolic links"},
150: {ENAMETOOLONG, "EX_NAMETOOLONG: File name too long"},
151: {EHOSTDOWN, "EX_HOSTDOWN: Host is down"},
152: {EHOSTUNREACH, "EX_HOSTUNREACH: No route to host"},
153: {ENOTEMPTY, "EX_NOTEMPTY: Directory not empty"},
154: {EDQUOT, "EX_DQUOT: Disk quota exceeded"},
155: {ENOLCK, "EX_NOLCK: No locks available"},
156: {ENOSYS, "EX_NOSYS: Function not implemented"},
157: {EFTYPE, "EX_FTYPE: Inappropriate file type or format"},
158: {EILSEQ, "EX_ILSEQ: Illegal byte sequence"},
159: {ENOTSUP, "EX_NOTSUP: Not supported"},
160: };
161:
162: EXPORT int strercd_r(ER er, char *buf, size_t buflen)
163: {
164: int i, n, mer, ser;
165: const char *p;
166:
167: p = NULL;
168: mer = MERCD(er);
169: if (mer != EC_ERRNO) {
170: for (i = 0; i < (int)(sizeof(e_tbl) / sizeof(*e_tbl)); i++) {
171: if (e_tbl[i].mer == mer) {
172: p = e_tbl[i].msg;
173: break;
174: }
175: }
176: } else {
177: ser = SERCD(er);
178: for (i = 0; i < (int)(sizeof(ex_tbl) / sizeof(*ex_tbl)); i++) {
179: if (ex_tbl[i].ser == ser) {
180: p = ex_tbl[i].msg;
181: break;
182: }
183: }
184: }
185:
186: if (p != NULL) {
187: n = strlen( p );
188: if (n + 1 > (int)buflen) goto e2;
189: strcpy( buf, p );
190: return 0;
191: }
192:
193: return EINVAL;
194: e2: return ERANGE;
195: }