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:
55: LOCAL const struct {
56: int er;
57: const char *msg;
58: } er_tbl[] = {
59: {EPERM, "EPERM: Operation not permitted"},
60: {ENOENT, "ENOENT: No such file or directory"},
61: {ESRCH, "ESRCH: No such process"},
62: {EINTR, "EINTR: Interrupted system call"},
63: {EIO, "EIO: Input/output error"},
64: {ENXIO, "ENXIO: Device not configured"},
65: {E2BIG, "E2BIG: Argument list too long"},
66: {ENOEXEC, "ENOEXEC: Exec format error"},
67: {EBADF, "EBADF: Bad file descriptor"},
68: {ECHILD, "ECHILD: No child processes"},
69: {EDEADLK, "EDEADLK: Resource deadlock avoided"},
70: {ENOMEM, "ENOMEM: Cannot allocate memory"},
71: {EACCES, "EACCES: Permission denied"},
72: {EFAULT, "EFAULT: Bad address"},
73: {EBUSY, "EBUSY: Device busy"},
74: {EEXIST, "EEXIST: File exists"},
75: {EXDEV, "EXDEV: Cross-device link"},
76: {ENODEV, "ENODEV: Operation not supported by device"},
77: {ENOTDIR, "ENOTDIR: Not a directory"},
78: {EISDIR, "EISDIR: Is a directory"},
79: {EINVAL, "EINVAL: Invalid argument"},
80: {ENFILE, "ENFILE: Too many open files in system"},
81: {EMFILE, "EMFILE: Too many open files"},
82: {ENOTTY, "ENOTTY: Inappropriate ioctl for device"},
83: {EFBIG, "EFBIG: File too large"},
84: {ENOSPC, "ENOSPC: No space left on device"},
85: {ESPIPE, "ESPIPE: Illegal seek"},
86: {EROFS, "EROFS: Read-only file system"},
87: {EMLINK, "EMLINK: Too many links"},
88: {EPIPE, "EPIPE: Broken pipe"},
89: {EDOM, "EDOM: Numerical argument out of domain"},
90: {ERANGE, "ERANGE: Result too large"},
91: {EAGAIN, "EAGAIN: Resource temporarily unavailable"},
92: {EINPROGRESS, "EINPROGRESS: Operation now in progress"},
93: {EALREADY, "EALREADY: Operation already in progress"},
94: {ENOTSOCK, "ENOTSOCK: Socket operation on non-socket"},
95: {EDESTADDRREQ, "EDESTADDRREQ: Destination address required"},
96: {EMSGSIZE, "EMSGSIZE: Message too long"},
97: {EPROTOTYPE, "EPROTOTYPE: Protocol wrong type for socket"},
98: {ENOPROTOOPT, "ENOPROTOOPT: Protocol not available"},
99: {EPROTONOSUPPORT, "EPROTONOSUPPORT: Protocol not supported"},
100: {ESOCKTNOSUPPORT, "ESOCKTNOSUPPORT: Socket type not supported"},
101: {EOPNOTSUPP, "EOPNOTSUPP: Operation not supported"},
102: {EPFNOSUPPORT, "EPFNOSUPPORT: Protocol family not supported"},
103: {EADDRINUSE, "EADDRINUSE: Address already in use"},
104: {EADDRNOTAVAIL, "EADDRNOTAVAIL: Can't assign requested address"},
105: {ENETDOWN, "ENETDOWN: Network is down"},
106: {ENETUNREACH, "ENETUNREACH: Network is unreachable"},
107: {ENETRESET, "ENETRESET: Network dropped connection on reset"},
108: {ECONNABORTED, "ECONNABORTED: Software caused connection abort"},
109: {ECONNRESET, "ECONNRESET: Connection reset by peer"},
110: {ENOBUFS, "ENOBUFS: No buffer space available"},
111: {EISCONN, "EISCONN: Socket is already connected"},
112: {ENOTCONN, "ENOTCONN: Socket is not connected"},
113: {ESHUTDOWN, "ESHUTDOWN: Can't send after socket shutdown"},
114: {ETIMEDOUT, "ETIMEDOUT: Operation timed out"},
115: {ECONNREFUSED, "ECONNREFUSED: Connection refused"},
116: {ELOOP, "ELOOP: Too many levels of symbolic links"},
117: {ENAMETOOLONG, "ENAMETOOLONG: File name too long"},
118: {EHOSTDOWN, "EHOSTDOWN: Host is down"},
119: {EHOSTUNREACH, "EHOSTUNREACH: No route to host"},
120: {ENOTEMPTY, "ENOTEMPTY: Directory not empty"},
121: {EDQUOT, "EDQUOT: Disk quota exceeded"},
122: {ENOLCK, "ENOLCK: No locks available"},
123: {ENOSYS, "ENOSYS: Function not implemented"},
124: {EFTYPE, "EFTYPE: Inappropriate file type or format"},
125: {EILSEQ, "EILSEQ: Illegal byte sequence"},
126: {ENOTSUP, "ENOTSUP: Not supported"},
127: };
128:
129: EXPORT int strerror_r(errno_t errnum, char *buf, size_t buflen)
130: {
131: int i, n;
132:
133: for (i = 0; i < (int)(sizeof(er_tbl) / sizeof(*er_tbl)); i++) {
134: if (er_tbl[i].er == errnum) {
135: n = strlen( er_tbl[i].msg );
136: if (n + 1 > (int)buflen) goto e2;
137: strcpy( buf, er_tbl[i].msg );
138: return 0;
139: }
140: }
141:
142: return EINVAL;
143: e2: return ERANGE;
144: }