errors_linux.odin 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //+private
  2. package os2
  3. import "core:sys/linux"
  4. _Platform_Error :: linux.Errno
  5. @(rodata)
  6. _errno_strings := [linux.Errno]string{
  7. .NONE = "",
  8. .EPERM = "Operation not permitted",
  9. .ENOENT = "No such file or directory",
  10. .ESRCH = "No such process",
  11. .EINTR = "Interrupted system call",
  12. .EIO = "Input/output error",
  13. .ENXIO = "No such device or address",
  14. .E2BIG = "Argument list too long",
  15. .ENOEXEC = "Exec format error",
  16. .EBADF = "Bad file descriptor",
  17. .ECHILD = "No child processes",
  18. .EAGAIN = "Resource temporarily unavailable",
  19. .ENOMEM = "Cannot allocate memory",
  20. .EACCES = "Permission denied",
  21. .EFAULT = "Bad address",
  22. .ENOTBLK = "Block device required",
  23. .EBUSY = "Device or resource busy",
  24. .EEXIST = "File exists",
  25. .EXDEV = "Invalid cross-device link",
  26. .ENODEV = "No such device",
  27. .ENOTDIR = "Not a directory",
  28. .EISDIR = "Is a directory",
  29. .EINVAL = "Invalid argument",
  30. .ENFILE = "Too many open files in system",
  31. .EMFILE = "Too many open files",
  32. .ENOTTY = "Inappropriate ioctl for device",
  33. .ETXTBSY = "Text file busy",
  34. .EFBIG = "File too large",
  35. .ENOSPC = "No space left on device",
  36. .ESPIPE = "Illegal seek",
  37. .EROFS = "Read-only file system",
  38. .EMLINK = "Too many links",
  39. .EPIPE = "Broken pipe",
  40. .EDOM = "Numerical argument out of domain",
  41. .ERANGE = "Numerical result out of range",
  42. .EDEADLK = "Resource deadlock avoided",
  43. .ENAMETOOLONG = "File name too long",
  44. .ENOLCK = "No locks available",
  45. .ENOSYS = "Function not implemented",
  46. .ENOTEMPTY = "Directory not empty",
  47. .ELOOP = "Too many levels of symbolic links",
  48. .EUNKNOWN_41 = "Unknown Error (41)",
  49. .ENOMSG = "No message of desired type",
  50. .EIDRM = "Identifier removed",
  51. .ECHRNG = "Channel number out of range",
  52. .EL2NSYNC = "Level 2 not synchronized",
  53. .EL3HLT = "Level 3 halted",
  54. .EL3RST = "Level 3 reset",
  55. .ELNRNG = "Link number out of range",
  56. .EUNATCH = "Protocol driver not attached",
  57. .ENOCSI = "No CSI structure available",
  58. .EL2HLT = "Level 2 halted",
  59. .EBADE = "Invalid exchange",
  60. .EBADR = "Invalid request descriptor",
  61. .EXFULL = "Exchange full",
  62. .ENOANO = "No anode",
  63. .EBADRQC = "Invalid request code",
  64. .EBADSLT = "Invalid slot",
  65. .EUNKNOWN_58 = "Unknown Error (58)",
  66. .EBFONT = "Bad font file format",
  67. .ENOSTR = "Device not a stream",
  68. .ENODATA = "No data available",
  69. .ETIME = "Timer expired",
  70. .ENOSR = "Out of streams resources",
  71. .ENONET = "Machine is not on the network",
  72. .ENOPKG = "Package not installed",
  73. .EREMOTE = "Object is remote",
  74. .ENOLINK = "Link has been severed",
  75. .EADV = "Advertise error",
  76. .ESRMNT = "Srmount error",
  77. .ECOMM = "Communication error on send",
  78. .EPROTO = "Protocol error",
  79. .EMULTIHOP = "Multihop attempted",
  80. .EDOTDOT = "RFS specific error",
  81. .EBADMSG = "Bad message",
  82. .EOVERFLOW = "Value too large for defined data type",
  83. .ENOTUNIQ = "Name not unique on network",
  84. .EBADFD = "File descriptor in bad state",
  85. .EREMCHG = "Remote address changed",
  86. .ELIBACC = "Can not access a needed shared library",
  87. .ELIBBAD = "Accessing a corrupted shared library",
  88. .ELIBSCN = ".lib section in a.out corrupted",
  89. .ELIBMAX = "Attempting to link in too many shared libraries",
  90. .ELIBEXEC = "Cannot exec a shared library directly",
  91. .EILSEQ = "Invalid or incomplete multibyte or wide character",
  92. .ERESTART = "Interrupted system call should be restarted",
  93. .ESTRPIPE = "Streams pipe error",
  94. .EUSERS = "Too many users",
  95. .ENOTSOCK = "Socket operation on non-socket",
  96. .EDESTADDRREQ = "Destination address required",
  97. .EMSGSIZE = "Message too long",
  98. .EPROTOTYPE = "Protocol wrong type for socket",
  99. .ENOPROTOOPT = "Protocol not available",
  100. .EPROTONOSUPPORT = "Protocol not supported",
  101. .ESOCKTNOSUPPORT = "Socket type not supported",
  102. .EOPNOTSUPP = "Operation not supported",
  103. .EPFNOSUPPORT = "Protocol family not supported",
  104. .EAFNOSUPPORT = "Address family not supported by protocol",
  105. .EADDRINUSE = "Address already in use",
  106. .EADDRNOTAVAIL = "Cannot assign requested address",
  107. .ENETDOWN = "Network is down",
  108. .ENETUNREACH = "Network is unreachable",
  109. .ENETRESET = "Network dropped connection on reset",
  110. .ECONNABORTED = "Software caused connection abort",
  111. .ECONNRESET = "Connection reset by peer",
  112. .ENOBUFS = "No buffer space available",
  113. .EISCONN = "Transport endpoint is already connected",
  114. .ENOTCONN = "Transport endpoint is not connected",
  115. .ESHUTDOWN = "Cannot send after transport endpoint shutdown",
  116. .ETOOMANYREFS = "Too many references: cannot splice",
  117. .ETIMEDOUT = "Connection timed out",
  118. .ECONNREFUSED = "Connection refused",
  119. .EHOSTDOWN = "Host is down",
  120. .EHOSTUNREACH = "No route to host",
  121. .EALREADY = "Operation already in progress",
  122. .EINPROGRESS = "Operation now in progress",
  123. .ESTALE = "Stale file handle",
  124. .EUCLEAN = "Structure needs cleaning",
  125. .ENOTNAM = "Not a XENIX named type file",
  126. .ENAVAIL = "No XENIX semaphores available",
  127. .EISNAM = "Is a named type file",
  128. .EREMOTEIO = "Remote I/O error",
  129. .EDQUOT = "Disk quota exceeded",
  130. .ENOMEDIUM = "No medium found",
  131. .EMEDIUMTYPE = "Wrong medium type",
  132. .ECANCELED = "Operation canceled",
  133. .ENOKEY = "Required key not available",
  134. .EKEYEXPIRED = "Key has expired",
  135. .EKEYREVOKED = "Key has been revoked",
  136. .EKEYREJECTED = "Key was rejected by service",
  137. .EOWNERDEAD = "Owner died",
  138. .ENOTRECOVERABLE = "State not recoverable",
  139. .ERFKILL = "Operation not possible due to RF-kill",
  140. .EHWPOISON = "Memory page has hardware error",
  141. }
  142. _get_platform_error :: proc(errno: linux.Errno) -> Error {
  143. #partial switch errno {
  144. case .NONE:
  145. return nil
  146. case .EPERM:
  147. return .Permission_Denied
  148. case .EEXIST:
  149. return .Exist
  150. case .ENOENT:
  151. return .Not_Exist
  152. case .ETIMEDOUT:
  153. return .Timeout
  154. case .EPIPE:
  155. return .Broken_Pipe
  156. case .EBADF:
  157. return .Invalid_File
  158. case .ENOMEM:
  159. return .Out_Of_Memory
  160. }
  161. return Platform_Error(i32(errno))
  162. }
  163. _error_string :: proc(errno: i32) -> string {
  164. if errno >= 0 && errno <= i32(max(linux.Errno)) {
  165. return _errno_strings[linux.Errno(errno)]
  166. }
  167. return "Unknown Error"
  168. }