mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-31 18:32:12 +00:00
change error strings to an enumerated array in rodata; print_error takes a file argument
This commit is contained in:
@@ -100,7 +100,7 @@ error_string :: proc(ferr: Error) -> string {
|
||||
return "unknown error"
|
||||
}
|
||||
|
||||
print_error :: proc(ferr: Error, msg: string) {
|
||||
print_error :: proc(f: ^File, ferr: Error, msg: string) {
|
||||
TEMP_ALLOCATOR_GUARD()
|
||||
err_str := error_string(ferr)
|
||||
|
||||
@@ -113,5 +113,5 @@ print_error :: proc(ferr: Error, msg: string) {
|
||||
buf[len(msg) + 1] = ' '
|
||||
copy(buf[len(msg) + 2:], err_str)
|
||||
buf[length - 1] = '\n'
|
||||
write(stderr, buf)
|
||||
write(f, buf)
|
||||
}
|
||||
|
||||
@@ -3,141 +3,142 @@ package os2
|
||||
|
||||
import "core:sys/linux"
|
||||
|
||||
_errno_strings : [int(max(linux.Errno)) + 1]string = {
|
||||
linux.Errno.NONE = "Success",
|
||||
linux.Errno.EPERM = "Operation not permitted",
|
||||
linux.Errno.ENOENT = "No such file or directory",
|
||||
linux.Errno.ESRCH = "No such process",
|
||||
linux.Errno.EINTR = "Interrupted system call",
|
||||
linux.Errno.EIO = "Input/output error",
|
||||
linux.Errno.ENXIO = "No such device or address",
|
||||
linux.Errno.E2BIG = "Argument list too long",
|
||||
linux.Errno.ENOEXEC = "Exec format error",
|
||||
linux.Errno.EBADF = "Bad file descriptor",
|
||||
linux.Errno.ECHILD = "No child processes",
|
||||
linux.Errno.EAGAIN = "Resource temporarily unavailable",
|
||||
linux.Errno.ENOMEM = "Cannot allocate memory",
|
||||
linux.Errno.EACCES = "Permission denied",
|
||||
linux.Errno.EFAULT = "Bad address",
|
||||
linux.Errno.ENOTBLK = "Block device required",
|
||||
linux.Errno.EBUSY = "Device or resource busy",
|
||||
linux.Errno.EEXIST = "File exists",
|
||||
linux.Errno.EXDEV = "Invalid cross-device link",
|
||||
linux.Errno.ENODEV = "No such device",
|
||||
linux.Errno.ENOTDIR = "Not a directory",
|
||||
linux.Errno.EISDIR = "Is a directory",
|
||||
linux.Errno.EINVAL = "Invalid argument",
|
||||
linux.Errno.ENFILE = "Too many open files in system",
|
||||
linux.Errno.EMFILE = "Too many open files",
|
||||
linux.Errno.ENOTTY = "Inappropriate ioctl for device",
|
||||
linux.Errno.ETXTBSY = "Text file busy",
|
||||
linux.Errno.EFBIG = "File too large",
|
||||
linux.Errno.ENOSPC = "No space left on device",
|
||||
linux.Errno.ESPIPE = "Illegal seek",
|
||||
linux.Errno.EROFS = "Read-only file system",
|
||||
linux.Errno.EMLINK = "Too many links",
|
||||
linux.Errno.EPIPE = "Broken pipe",
|
||||
linux.Errno.EDOM = "Numerical argument out of domain",
|
||||
linux.Errno.ERANGE = "Numerical result out of range",
|
||||
linux.Errno.EDEADLK = "Resource deadlock avoided",
|
||||
linux.Errno.ENAMETOOLONG = "File name too long",
|
||||
linux.Errno.ENOLCK = "No locks available",
|
||||
linux.Errno.ENOSYS = "Function not implemented",
|
||||
linux.Errno.ENOTEMPTY = "Directory not empty",
|
||||
linux.Errno.ELOOP = "Too many levels of symbolic links",
|
||||
41 = "Unknown Error (41)",
|
||||
linux.Errno.ENOMSG = "No message of desired type",
|
||||
linux.Errno.EIDRM = "Identifier removed",
|
||||
linux.Errno.ECHRNG = "Channel number out of range",
|
||||
linux.Errno.EL2NSYNC = "Level 2 not synchronized",
|
||||
linux.Errno.EL3HLT = "Level 3 halted",
|
||||
linux.Errno.EL3RST = "Level 3 reset",
|
||||
linux.Errno.ELNRNG = "Link number out of range",
|
||||
linux.Errno.EUNATCH = "Protocol driver not attached",
|
||||
linux.Errno.ENOCSI = "No CSI structure available",
|
||||
linux.Errno.EL2HLT = "Level 2 halted",
|
||||
linux.Errno.EBADE = "Invalid exchange",
|
||||
linux.Errno.EBADR = "Invalid request descriptor",
|
||||
linux.Errno.EXFULL = "Exchange full",
|
||||
linux.Errno.ENOANO = "No anode",
|
||||
linux.Errno.EBADRQC = "Invalid request code",
|
||||
linux.Errno.EBADSLT = "Invalid slot",
|
||||
58 = "Unknown Error (58)",
|
||||
linux.Errno.EBFONT = "Bad font file format",
|
||||
linux.Errno.ENOSTR = "Device not a stream",
|
||||
linux.Errno.ENODATA = "No data available",
|
||||
linux.Errno.ETIME = "Timer expired",
|
||||
linux.Errno.ENOSR = "Out of streams resources",
|
||||
linux.Errno.ENONET = "Machine is not on the network",
|
||||
linux.Errno.ENOPKG = "Package not installed",
|
||||
linux.Errno.EREMOTE = "Object is remote",
|
||||
linux.Errno.ENOLINK = "Link has been severed",
|
||||
linux.Errno.EADV = "Advertise error",
|
||||
linux.Errno.ESRMNT = "Srmount error",
|
||||
linux.Errno.ECOMM = "Communication error on send",
|
||||
linux.Errno.EPROTO = "Protocol error",
|
||||
linux.Errno.EMULTIHOP = "Multihop attempted",
|
||||
linux.Errno.EDOTDOT = "RFS specific error",
|
||||
linux.Errno.EBADMSG = "Bad message",
|
||||
linux.Errno.EOVERFLOW = "Value too large for defined data type",
|
||||
linux.Errno.ENOTUNIQ = "Name not unique on network",
|
||||
linux.Errno.EBADFD = "File descriptor in bad state",
|
||||
linux.Errno.EREMCHG = "Remote address changed",
|
||||
linux.Errno.ELIBACC = "Can not access a needed shared library",
|
||||
linux.Errno.ELIBBAD = "Accessing a corrupted shared library",
|
||||
linux.Errno.ELIBSCN = ".lib section in a.out corrupted",
|
||||
linux.Errno.ELIBMAX = "Attempting to link in too many shared libraries",
|
||||
linux.Errno.ELIBEXEC = "Cannot exec a shared library directly",
|
||||
linux.Errno.EILSEQ = "Invalid or incomplete multibyte or wide character",
|
||||
linux.Errno.ERESTART = "Interrupted system call should be restarted",
|
||||
linux.Errno.ESTRPIPE = "Streams pipe error",
|
||||
linux.Errno.EUSERS = "Too many users",
|
||||
linux.Errno.ENOTSOCK = "Socket operation on non-socket",
|
||||
linux.Errno.EDESTADDRREQ = "Destination address required",
|
||||
linux.Errno.EMSGSIZE = "Message too long",
|
||||
linux.Errno.EPROTOTYPE = "Protocol wrong type for socket",
|
||||
linux.Errno.ENOPROTOOPT = "Protocol not available",
|
||||
linux.Errno.EPROTONOSUPPORT = "Protocol not supported",
|
||||
linux.Errno.ESOCKTNOSUPPORT = "Socket type not supported",
|
||||
linux.Errno.EOPNOTSUPP = "Operation not supported",
|
||||
linux.Errno.EPFNOSUPPORT = "Protocol family not supported",
|
||||
linux.Errno.EAFNOSUPPORT = "Address family not supported by protocol",
|
||||
linux.Errno.EADDRINUSE = "Address already in use",
|
||||
linux.Errno.EADDRNOTAVAIL = "Cannot assign requested address",
|
||||
linux.Errno.ENETDOWN = "Network is down",
|
||||
linux.Errno.ENETUNREACH = "Network is unreachable",
|
||||
linux.Errno.ENETRESET = "Network dropped connection on reset",
|
||||
linux.Errno.ECONNABORTED = "Software caused connection abort",
|
||||
linux.Errno.ECONNRESET = "Connection reset by peer",
|
||||
linux.Errno.ENOBUFS = "No buffer space available",
|
||||
linux.Errno.EISCONN = "Transport endpoint is already connected",
|
||||
linux.Errno.ENOTCONN = "Transport endpoint is not connected",
|
||||
linux.Errno.ESHUTDOWN = "Cannot send after transport endpoint shutdown",
|
||||
linux.Errno.ETOOMANYREFS = "Too many references: cannot splice",
|
||||
linux.Errno.ETIMEDOUT = "Connection timed out",
|
||||
linux.Errno.ECONNREFUSED = "Connection refused",
|
||||
linux.Errno.EHOSTDOWN = "Host is down",
|
||||
linux.Errno.EHOSTUNREACH = "No route to host",
|
||||
linux.Errno.EALREADY = "Operation already in progress",
|
||||
linux.Errno.EINPROGRESS = "Operation now in progress",
|
||||
linux.Errno.ESTALE = "Stale file handle",
|
||||
linux.Errno.EUCLEAN = "Structure needs cleaning",
|
||||
linux.Errno.ENOTNAM = "Not a XENIX named type file",
|
||||
linux.Errno.ENAVAIL = "No XENIX semaphores available",
|
||||
linux.Errno.EISNAM = "Is a named type file",
|
||||
linux.Errno.EREMOTEIO = "Remote I/O error",
|
||||
linux.Errno.EDQUOT = "Disk quota exceeded",
|
||||
linux.Errno.ENOMEDIUM = "No medium found",
|
||||
linux.Errno.EMEDIUMTYPE = "Wrong medium type",
|
||||
linux.Errno.ECANCELED = "Operation canceled",
|
||||
linux.Errno.ENOKEY = "Required key not available",
|
||||
linux.Errno.EKEYEXPIRED = "Key has expired",
|
||||
linux.Errno.EKEYREVOKED = "Key has been revoked",
|
||||
linux.Errno.EKEYREJECTED = "Key was rejected by service",
|
||||
linux.Errno.EOWNERDEAD = "Owner died",
|
||||
linux.Errno.ENOTRECOVERABLE = "State not recoverable",
|
||||
linux.Errno.ERFKILL = "Operation not possible due to RF-kill",
|
||||
linux.Errno.EHWPOISON = "Memory page has hardware error",
|
||||
@(rodata)
|
||||
_errno_strings : [linux.Errno]string = {
|
||||
.NONE = "Success",
|
||||
.EPERM = "Operation not permitted",
|
||||
.ENOENT = "No such file or directory",
|
||||
.ESRCH = "No such process",
|
||||
.EINTR = "Interrupted system call",
|
||||
.EIO = "Input/output error",
|
||||
.ENXIO = "No such device or address",
|
||||
.E2BIG = "Argument list too long",
|
||||
.ENOEXEC = "Exec format error",
|
||||
.EBADF = "Bad file descriptor",
|
||||
.ECHILD = "No child processes",
|
||||
.EAGAIN = "Resource temporarily unavailable",
|
||||
.ENOMEM = "Cannot allocate memory",
|
||||
.EACCES = "Permission denied",
|
||||
.EFAULT = "Bad address",
|
||||
.ENOTBLK = "Block device required",
|
||||
.EBUSY = "Device or resource busy",
|
||||
.EEXIST = "File exists",
|
||||
.EXDEV = "Invalid cross-device link",
|
||||
.ENODEV = "No such device",
|
||||
.ENOTDIR = "Not a directory",
|
||||
.EISDIR = "Is a directory",
|
||||
.EINVAL = "Invalid argument",
|
||||
.ENFILE = "Too many open files in system",
|
||||
.EMFILE = "Too many open files",
|
||||
.ENOTTY = "Inappropriate ioctl for device",
|
||||
.ETXTBSY = "Text file busy",
|
||||
.EFBIG = "File too large",
|
||||
.ENOSPC = "No space left on device",
|
||||
.ESPIPE = "Illegal seek",
|
||||
.EROFS = "Read-only file system",
|
||||
.EMLINK = "Too many links",
|
||||
.EPIPE = "Broken pipe",
|
||||
.EDOM = "Numerical argument out of domain",
|
||||
.ERANGE = "Numerical result out of range",
|
||||
.EDEADLK = "Resource deadlock avoided",
|
||||
.ENAMETOOLONG = "File name too long",
|
||||
.ENOLCK = "No locks available",
|
||||
.ENOSYS = "Function not implemented",
|
||||
.ENOTEMPTY = "Directory not empty",
|
||||
.ELOOP = "Too many levels of symbolic links",
|
||||
.EUNKNOWN_41 = "Unknown Error (41)",
|
||||
.ENOMSG = "No message of desired type",
|
||||
.EIDRM = "Identifier removed",
|
||||
.ECHRNG = "Channel number out of range",
|
||||
.EL2NSYNC = "Level 2 not synchronized",
|
||||
.EL3HLT = "Level 3 halted",
|
||||
.EL3RST = "Level 3 reset",
|
||||
.ELNRNG = "Link number out of range",
|
||||
.EUNATCH = "Protocol driver not attached",
|
||||
.ENOCSI = "No CSI structure available",
|
||||
.EL2HLT = "Level 2 halted",
|
||||
.EBADE = "Invalid exchange",
|
||||
.EBADR = "Invalid request descriptor",
|
||||
.EXFULL = "Exchange full",
|
||||
.ENOANO = "No anode",
|
||||
.EBADRQC = "Invalid request code",
|
||||
.EBADSLT = "Invalid slot",
|
||||
.EUNKNOWN_58 = "Unknown Error (58)",
|
||||
.EBFONT = "Bad font file format",
|
||||
.ENOSTR = "Device not a stream",
|
||||
.ENODATA = "No data available",
|
||||
.ETIME = "Timer expired",
|
||||
.ENOSR = "Out of streams resources",
|
||||
.ENONET = "Machine is not on the network",
|
||||
.ENOPKG = "Package not installed",
|
||||
.EREMOTE = "Object is remote",
|
||||
.ENOLINK = "Link has been severed",
|
||||
.EADV = "Advertise error",
|
||||
.ESRMNT = "Srmount error",
|
||||
.ECOMM = "Communication error on send",
|
||||
.EPROTO = "Protocol error",
|
||||
.EMULTIHOP = "Multihop attempted",
|
||||
.EDOTDOT = "RFS specific error",
|
||||
.EBADMSG = "Bad message",
|
||||
.EOVERFLOW = "Value too large for defined data type",
|
||||
.ENOTUNIQ = "Name not unique on network",
|
||||
.EBADFD = "File descriptor in bad state",
|
||||
.EREMCHG = "Remote address changed",
|
||||
.ELIBACC = "Can not access a needed shared library",
|
||||
.ELIBBAD = "Accessing a corrupted shared library",
|
||||
.ELIBSCN = ".lib section in a.out corrupted",
|
||||
.ELIBMAX = "Attempting to link in too many shared libraries",
|
||||
.ELIBEXEC = "Cannot exec a shared library directly",
|
||||
.EILSEQ = "Invalid or incomplete multibyte or wide character",
|
||||
.ERESTART = "Interrupted system call should be restarted",
|
||||
.ESTRPIPE = "Streams pipe error",
|
||||
.EUSERS = "Too many users",
|
||||
.ENOTSOCK = "Socket operation on non-socket",
|
||||
.EDESTADDRREQ = "Destination address required",
|
||||
.EMSGSIZE = "Message too long",
|
||||
.EPROTOTYPE = "Protocol wrong type for socket",
|
||||
.ENOPROTOOPT = "Protocol not available",
|
||||
.EPROTONOSUPPORT = "Protocol not supported",
|
||||
.ESOCKTNOSUPPORT = "Socket type not supported",
|
||||
.EOPNOTSUPP = "Operation not supported",
|
||||
.EPFNOSUPPORT = "Protocol family not supported",
|
||||
.EAFNOSUPPORT = "Address family not supported by protocol",
|
||||
.EADDRINUSE = "Address already in use",
|
||||
.EADDRNOTAVAIL = "Cannot assign requested address",
|
||||
.ENETDOWN = "Network is down",
|
||||
.ENETUNREACH = "Network is unreachable",
|
||||
.ENETRESET = "Network dropped connection on reset",
|
||||
.ECONNABORTED = "Software caused connection abort",
|
||||
.ECONNRESET = "Connection reset by peer",
|
||||
.ENOBUFS = "No buffer space available",
|
||||
.EISCONN = "Transport endpoint is already connected",
|
||||
.ENOTCONN = "Transport endpoint is not connected",
|
||||
.ESHUTDOWN = "Cannot send after transport endpoint shutdown",
|
||||
.ETOOMANYREFS = "Too many references: cannot splice",
|
||||
.ETIMEDOUT = "Connection timed out",
|
||||
.ECONNREFUSED = "Connection refused",
|
||||
.EHOSTDOWN = "Host is down",
|
||||
.EHOSTUNREACH = "No route to host",
|
||||
.EALREADY = "Operation already in progress",
|
||||
.EINPROGRESS = "Operation now in progress",
|
||||
.ESTALE = "Stale file handle",
|
||||
.EUCLEAN = "Structure needs cleaning",
|
||||
.ENOTNAM = "Not a XENIX named type file",
|
||||
.ENAVAIL = "No XENIX semaphores available",
|
||||
.EISNAM = "Is a named type file",
|
||||
.EREMOTEIO = "Remote I/O error",
|
||||
.EDQUOT = "Disk quota exceeded",
|
||||
.ENOMEDIUM = "No medium found",
|
||||
.EMEDIUMTYPE = "Wrong medium type",
|
||||
.ECANCELED = "Operation canceled",
|
||||
.ENOKEY = "Required key not available",
|
||||
.EKEYEXPIRED = "Key has expired",
|
||||
.EKEYREVOKED = "Key has been revoked",
|
||||
.EKEYREJECTED = "Key was rejected by service",
|
||||
.EOWNERDEAD = "Owner died",
|
||||
.ENOTRECOVERABLE = "State not recoverable",
|
||||
.ERFKILL = "Operation not possible due to RF-kill",
|
||||
.EHWPOISON = "Memory page has hardware error",
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +159,7 @@ _get_platform_error :: proc(errno: linux.Errno) -> Error {
|
||||
|
||||
_error_string :: proc(errno: i32) -> string {
|
||||
if errno >= 0 && errno <= i32(max(linux.Errno)) {
|
||||
return _errno_strings[errno]
|
||||
return _errno_strings[linux.Errno(errno)]
|
||||
}
|
||||
return "Unknown Error"
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ _process_start :: proc(name: string, argv: []string, attr: ^Process_Attributes)
|
||||
}
|
||||
|
||||
if errno = linux.execveat(dir_fd, executable, &cargs[OUT], env); errno != .NONE {
|
||||
print_error(_get_platform_error(errno), string(executable))
|
||||
print_error(stderr, _get_platform_error(errno), string(executable))
|
||||
panic("execve failed to replace process")
|
||||
}
|
||||
unreachable()
|
||||
|
||||
@@ -48,6 +48,7 @@ Errno :: enum i32 {
|
||||
ENOSYS = 38,
|
||||
ENOTEMPTY = 39,
|
||||
ELOOP = 40,
|
||||
EUNKNOWN_41 = 41,
|
||||
ENOMSG = 42,
|
||||
EIDRM = 43,
|
||||
ECHRNG = 44,
|
||||
@@ -64,6 +65,7 @@ Errno :: enum i32 {
|
||||
ENOANO = 55,
|
||||
EBADRQC = 56,
|
||||
EBADSLT = 57,
|
||||
EUNKNOWN_58 = 58,
|
||||
EBFONT = 59,
|
||||
ENOSTR = 60,
|
||||
ENODATA = 61,
|
||||
|
||||
Reference in New Issue
Block a user