errno_str.c 6.4 KB

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