1 /*
2  * Copyright (C) 2014 Samsung Electronics
3  * Przemyslaw Marczak <p.marczak@samsung.com>
4  *
5  * SDPX-License-Identifier:	GPL-2.0+
6  */
7 #include <common.h>
8 #include <errno.h>
9 
10 #define ERRNO_MSG(errno, msg)	msg
11 #define SAME_AS(x)		(const char *)&errno_message[x]
12 
13 static const char * const errno_message[] = {
14 	ERRNO_MSG(0, "Success"),
15 	ERRNO_MSG(EPERM, "Operation not permitted"),
16 	ERRNO_MSG(ENOEN, "No such file or directory"),
17 	ERRNO_MSG(ESRCH, "No such process"),
18 	ERRNO_MSG(EINTR, "Interrupted system call"),
19 	ERRNO_MSG(EIO, "I/O error"),
20 	ERRNO_MSG(ENXIO, "No such device or address"),
21 	ERRNO_MSG(E2BIG, "Argument list too long"),
22 	ERRNO_MSG(ENOEXEC, "Exec format error"),
23 	ERRNO_MSG(EBADF, "Bad file number"),
24 	ERRNO_MSG(ECHILD, "No child processes"),
25 	ERRNO_MSG(EAGAIN, "Try again"),
26 	ERRNO_MSG(ENOMEM, "Out of memory"),
27 	ERRNO_MSG(EACCES, "Permission denied"),
28 	ERRNO_MSG(EFAULT, "Bad address"),
29 	ERRNO_MSG(ENOTBL, "Block device required"),
30 	ERRNO_MSG(EBUSY, "Device or resource busy"),
31 	ERRNO_MSG(EEXIST, "File exists"),
32 	ERRNO_MSG(EXDEV, "Cross-device link"),
33 	ERRNO_MSG(ENODEV, "No such device"),
34 	ERRNO_MSG(ENOTDIR, "Not a directory"),
35 	ERRNO_MSG(EISDIR, "Is a directory"),
36 	ERRNO_MSG(EINVAL, "Invalid argument"),
37 	ERRNO_MSG(ENFILE, "File table overflow"),
38 	ERRNO_MSG(EMFILE, "Too many open files"),
39 	ERRNO_MSG(ENOTTY, "Not a typewriter"),
40 	ERRNO_MSG(ETXTBSY, "Text file busy"),
41 	ERRNO_MSG(EFBIG, "File too large"),
42 	ERRNO_MSG(ENOSPC, "No space left on device"),
43 	ERRNO_MSG(ESPIPE, "Illegal seek"),
44 	ERRNO_MSG(EROFS, "Read-only file system"),
45 	ERRNO_MSG(EMLINK, "Too many links"),
46 	ERRNO_MSG(EPIPE, "Broken pipe"),
47 	ERRNO_MSG(EDOM, "Math argument out of domain of func"),
48 	ERRNO_MSG(ERANGE, "Math result not representable"),
49 	ERRNO_MSG(EDEADLK, "Resource deadlock would occur"),
50 	ERRNO_MSG(ENAMETOOLONG, "File name too long"),
51 	ERRNO_MSG(ENOLCK, "No record locks available"),
52 	ERRNO_MSG(ENOSYS, "Function not implemented"),
53 	ERRNO_MSG(ENOTEMPTY, "Directory not empty"),
54 	ERRNO_MSG(ELOOP, "Too many symbolic links encountered"),
55 	ERRNO_MSG(EWOULDBLOCK, SAME_AS(EAGAIN)),
56 	ERRNO_MSG(ENOMSG, "No message of desired type"),
57 	ERRNO_MSG(EIDRM, "Identifier removed"),
58 	ERRNO_MSG(ECHRNG, "Channel number out of range"),
59 	ERRNO_MSG(EL2NSYNC, "Level 2 not synchronized"),
60 	ERRNO_MSG(EL3HLT, "Level 3 halted"),
61 	ERRNO_MSG(EL3RST, "Level 3 reset"),
62 	ERRNO_MSG(ELNRNG, "Link number out of range"),
63 	ERRNO_MSG(EUNATCH, "Protocol driver not attached"),
64 	ERRNO_MSG(ENOCSI, "No CSI structure available"),
65 	ERRNO_MSG(EL2HLT, "Level 2 halted"),
66 	ERRNO_MSG(EBADE, "Invalid exchange"),
67 	ERRNO_MSG(EBADR, "Invalid request descriptor"),
68 	ERRNO_MSG(EXFULL, "Exchange full"),
69 	ERRNO_MSG(ENOANO, "No anode"),
70 	ERRNO_MSG(EBADRQC, "Invalid request code"),
71 	ERRNO_MSG(EBADSLT, "Invalid slot"),
72 	ERRNO_MSG(EDEADLOCK, SAME_AS(EDEADLK)),
73 	ERRNO_MSG(EBFONT, "Bad font file format"),
74 	ERRNO_MSG(ENOSTR, "Device not a stream"),
75 	ERRNO_MSG(ENODATA, "No data available"),
76 	ERRNO_MSG(ETIME, "Timer expired"),
77 	ERRNO_MSG(ENOSR, "Out of streams resources"),
78 	ERRNO_MSG(ENONET, "Machine is not on the network"),
79 	ERRNO_MSG(ENOPKG, "Package not installed"),
80 	ERRNO_MSG(EREMOTE, "Object is remote"),
81 	ERRNO_MSG(ENOLINK, "Link has been severed"),
82 	ERRNO_MSG(EADV, "Advertise error"),
83 	ERRNO_MSG(ESRMNT, "Srmount error"),
84 	ERRNO_MSG(ECOMM, "Communication error on send"),
85 	ERRNO_MSG(EPROTO, "Protocol error"),
86 	ERRNO_MSG(EMULTIHOP, "Multihop attempted"),
87 	ERRNO_MSG(EDOTDOT, "RFS specific error"),
88 	ERRNO_MSG(EBADMSG, "Not a data message"),
89 	ERRNO_MSG(EOVERFLOW, "Value too large for defined data type"),
90 	ERRNO_MSG(ENOTUNIQ, "Name not unique on network"),
91 	ERRNO_MSG(EBADFD, "File descriptor in bad state"),
92 	ERRNO_MSG(EREMCHG, "Remote address changed"),
93 	ERRNO_MSG(ELIBACC, "Can not access a needed shared library"),
94 	ERRNO_MSG(ELIBBAD, "Accessing a corrupted shared library"),
95 	ERRNO_MSG(ELIBSCN, ".lib section in a.out corrupted"),
96 	ERRNO_MSG(ELIBMAX, "Attempting to link in too many shared libraries"),
97 	ERRNO_MSG(ELIBEXEC, "Cannot exec a shared library directly"),
98 	ERRNO_MSG(EILSEQ, "Illegal byte sequence"),
99 	ERRNO_MSG(ERESTART, "Interrupted system call should be restarted"),
100 	ERRNO_MSG(ESTRPIPE, "Streams pipe error"),
101 	ERRNO_MSG(EUSERS, "Too many users"),
102 	ERRNO_MSG(ENOTSOCK, "Socket operation on non-socket"),
103 	ERRNO_MSG(EDESTADDRREQ, "Destination address required"),
104 	ERRNO_MSG(EMSGSIZE, "Message too long"),
105 	ERRNO_MSG(EPROTOTYPE, "Protocol wrong type for socket"),
106 	ERRNO_MSG(ENOPROTOOPT, "Protocol not available"),
107 	ERRNO_MSG(EPROTONOSUPPORT, "Protocol not supported"),
108 	ERRNO_MSG(ESOCKTNOSUPPORT, "Socket type not supported"),
109 	ERRNO_MSG(EOPNOTSUPP, "Operation not supported on transport endpoint"),
110 	ERRNO_MSG(EPFNOSUPPORT, "Protocol family not supported"),
111 	ERRNO_MSG(AFNOSUPPORT, "Address family not supported by protocol"),
112 	ERRNO_MSG(EADDRINUSE, "Address already in use"),
113 	ERRNO_MSG(EADDRNOTAVAIL, "Cannot assign requested address"),
114 	ERRNO_MSG(ENETDOWN, "Network is down"),
115 	ERRNO_MSG(ENETUNREACH, "Network is unreachable"),
116 	ERRNO_MSG(ENETRESET, "Network dropped connection because of reset"),
117 	ERRNO_MSG(ECONNABORTED, "Software caused connection abort"),
118 	ERRNO_MSG(ECONNRESET, "Connection reset by peer"),
119 	ERRNO_MSG(ENOBUFS, "No buffer space available"),
120 	ERRNO_MSG(EISCONN, "Transport endpoint is already connected"),
121 	ERRNO_MSG(ENOTCONN, "Transport endpoint is not connected"),
122 	ERRNO_MSG(ESHUTDOWN, "Cannot send after transport endpoint shutdown"),
123 	ERRNO_MSG(ETOOMANYREFS, "Too many references: cannot splice"),
124 	ERRNO_MSG(ETIMEDOUT, "Connection timed out"),
125 	ERRNO_MSG(ECONNREFUSED, "Connection refused"),
126 	ERRNO_MSG(EHOSTDOWN, "Host is down"),
127 	ERRNO_MSG(EHOSTUNREACH, "No route to host"),
128 	ERRNO_MSG(EALREADY, "Operation already in progress"),
129 	ERRNO_MSG(EINPROGRESS, "Operation now in progress"),
130 	ERRNO_MSG(ESTALE, "Stale NFS file handle"),
131 	ERRNO_MSG(EUCLEAN, "Structure needs cleaning"),
132 	ERRNO_MSG(ENOTNAM, "Not a XENIX named type file"),
133 	ERRNO_MSG(ENAVAIL, "No XENIX semaphores available"),
134 	ERRNO_MSG(EISNAM, "Is a named type file"),
135 	ERRNO_MSG(EREMOTEIO, "Remote I/O error"),
136 	ERRNO_MSG(EDQUOT, "Quota exceeded"),
137 	ERRNO_MSG(ENOMEDIUM, "No medium found"),
138 	ERRNO_MSG(EMEDIUMTYPE, "Wrong medium type"),
139 };
140 
errno_str(int errno)141 const char *errno_str(int errno)
142 {
143 	if (errno >= 0)
144 		return errno_message[0];
145 
146 	return errno_message[abs(errno)];
147 }
148