Begin converting os.Errno to be a nil-able type as a transition period

This commit is contained in:
gingerBill
2024-08-04 10:51:08 +01:00
parent 71932628cc
commit e60951a902
22 changed files with 1165 additions and 666 deletions
+243 -104
View File
@@ -9,148 +9,287 @@ import "core:c"
Handle :: distinct i32
File_Time :: distinct u64
Errno :: distinct i32
INVALID_HANDLE :: ~Handle(0)
ERROR_NONE: Errno : 0 /* No error */
EPERM: Errno : 1 /* Operation not permitted */
ENOENT: Errno : 2 /* No such file or directory */
EINTR: Errno : 4 /* Interrupted system call */
ESRCH: Errno : 3 /* No such process */
EIO: Errno : 5 /* Input/output error */
ENXIO: Errno : 6 /* Device not configured */
E2BIG: Errno : 7 /* Argument list too long */
ENOEXEC: Errno : 8 /* Exec format error */
EBADF: Errno : 9 /* Bad file descriptor */
ECHILD: Errno : 10 /* No child processes */
EDEADLK: Errno : 11 /* Resource deadlock avoided. 11 was EAGAIN */
ENOMEM: Errno : 12 /* Cannot allocate memory */
EACCES: Errno : 13 /* Permission denied */
EFAULT: Errno : 14 /* Bad address */
ENOTBLK: Errno : 15 /* Block device required */
EBUSY: Errno : 16 /* Device busy */
EEXIST: Errno : 17 /* File exists */
EXDEV: Errno : 18 /* Cross-device link */
ENODEV: Errno : 19 /* Operation not supported by device */
ENOTDIR: Errno : 20 /* Not a directory */
EISDIR: Errno : 21 /* Is a directory */
EINVAL: Errno : 22 /* Invalid argument */
ENFILE: Errno : 23 /* Too many open files in system */
EMFILE: Errno : 24 /* Too many open files */
ENOTTY: Errno : 25 /* Inappropriate ioctl for device */
ETXTBSY: Errno : 26 /* Text file busy */
EFBIG: Errno : 27 /* File too large */
ENOSPC: Errno : 28 /* No space left on device */
ESPIPE: Errno : 29 /* Illegal seek */
EROFS: Errno : 30 /* Read-only file system */
EMLINK: Errno : 31 /* Too many links */
EPIPE: Errno : 32 /* Broken pipe */
_Platform_Error :: enum i32 {
NONE = 0,
EPERM = 1, /* Operation not permitted */
ENOENT = 2, /* No such file or directory */
EINTR = 4, /* Interrupted system call */
ESRCH = 3, /* No such process */
EIO = 5, /* Input/output error */
ENXIO = 6, /* Device not configured */
E2BIG = 7, /* Argument list too long */
ENOEXEC = 8, /* Exec format error */
EBADF = 9, /* Bad file descriptor */
ECHILD = 10, /* No child processes */
EDEADLK = 11, /* Resource deadlock avoided. 11 was EAGAIN */
ENOMEM = 12, /* Cannot allocate memory */
EACCES = 13, /* Permission denied */
EFAULT = 14, /* Bad address */
ENOTBLK = 15, /* Block device required */
EBUSY = 16, /* Device busy */
EEXIST = 17, /* File exists */
EXDEV = 18, /* Cross-device link */
ENODEV = 19, /* Operation not supported by device */
ENOTDIR = 20, /* Not a directory */
EISDIR = 21, /* Is a directory */
EINVAL = 22, /* Invalid argument */
ENFILE = 23, /* Too many open files in system */
EMFILE = 24, /* Too many open files */
ENOTTY = 25, /* Inappropriate ioctl for device */
ETXTBSY = 26, /* Text file busy */
EFBIG = 27, /* File too large */
ENOSPC = 28, /* No space left on device */
ESPIPE = 29, /* Illegal seek */
EROFS = 30, /* Read-only file system */
EMLINK = 31, /* Too many links */
EPIPE = 32, /* Broken pipe */
/* math software */
EDOM = 33, /* Numerical argument out of domain */
ERANGE = 34, /* Result too large or too small */
/* non-blocking and interrupt i/o */
EAGAIN = 35, /* Resource temporarily unavailable */
EWOULDBLOCK = EAGAIN, /* Operation would block */
EINPROGRESS = 36, /* Operation now in progress */
EALREADY = 37, /* Operation already in progress */
/* ipc/network software -- argument errors */
ENOTSOCK = 38, /* Socket operation on non-socket */
EDESTADDRREQ = 39, /* Destination address required */
EMSGSIZE = 40, /* Message too long */
EPROTOTYPE = 41, /* Protocol wrong type for socket */
ENOPROTOOPT = 42, /* Protocol option not available */
EPROTONOSUPPORT = 43, /* Protocol not supported */
ESOCKTNOSUPPORT = 44, /* Socket type not supported */
EOPNOTSUPP = 45, /* Operation not supported */
EPFNOSUPPORT = 46, /* Protocol family not supported */
EAFNOSUPPORT = 47, /* Address family not supported by protocol family */
EADDRINUSE = 48, /* Address already in use */
EADDRNOTAVAIL = 49, /* Can't assign requested address */
/* ipc/network software -- operational errors */
ENETDOWN = 50, /* Network is down */
ENETUNREACH = 51, /* Network is unreachable */
ENETRESET = 52, /* Network dropped connection on reset */
ECONNABORTED = 53, /* Software caused connection abort */
ECONNRESET = 54, /* Connection reset by peer */
ENOBUFS = 55, /* No buffer space available */
EISCONN = 56, /* Socket is already connected */
ENOTCONN = 57, /* Socket is not connected */
ESHUTDOWN = 58, /* Can't send after socket shutdown */
ETOOMANYREFS = 59, /* Too many references: can't splice */
ETIMEDOUT = 60, /* Operation timed out */
ECONNREFUSED = 61, /* Connection refused */
ELOOP = 62, /* Too many levels of symbolic links */
ENAMETOOLONG = 63, /* File name too long */
/* should be rearranged */
EHOSTDOWN = 64, /* Host is down */
EHOSTUNREACH = 65, /* No route to host */
ENOTEMPTY = 66, /* Directory not empty */
/* quotas & mush */
EPROCLIM = 67, /* Too many processes */
EUSERS = 68, /* Too many users */
EDQUOT = 69, /* Disc quota exceeded */
/* Network File System */
ESTALE = 70, /* Stale NFS file handle */
EREMOTE = 71, /* Too many levels of remote in path */
EBADRPC = 72, /* RPC struct is bad */
ERPCMISMATCH = 73, /* RPC version wrong */
EPROGUNAVAIL = 74, /* RPC prog. not avail */
EPROGMISMATCH = 75, /* Program version wrong */
EPROCUNAVAIL = 76, /* Bad procedure for program */
ENOLCK = 77, /* No locks available */
ENOSYS = 78, /* Function not implemented */
EFTYPE = 79, /* Inappropriate file type or format */
EAUTH = 80, /* Authentication error */
ENEEDAUTH = 81, /* Need authenticator */
/* SystemV IPC */
EIDRM = 82, /* Identifier removed */
ENOMSG = 83, /* No message of desired type */
EOVERFLOW = 84, /* Value too large to be stored in data type */
/* Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 */
EILSEQ = 85, /* Illegal byte sequence */
/* From IEEE Std 1003.1-2001 */
/* Base, Realtime, Threads or Thread Priority Scheduling option errors */
ENOTSUP = 86, /* Not supported */
/* Realtime option errors */
ECANCELED = 87, /* Operation canceled */
/* Realtime, XSI STREAMS option errors */
EBADMSG = 88, /* Bad or Corrupt message */
/* XSI STREAMS option errors */
ENODATA = 89, /* No message available */
ENOSR = 90, /* No STREAM resources */
ENOSTR = 91, /* Not a STREAM */
ETIME = 92, /* STREAM ioctl timeout */
/* File system extended attribute errors */
ENOATTR = 93, /* Attribute not found */
/* Realtime, XSI STREAMS option errors */
EMULTIHOP = 94, /* Multihop attempted */
ENOLINK = 95, /* Link has been severed */
EPROTO = 96, /* Protocol error */
/* Robust mutexes */
EOWNERDEAD = 97, /* Previous owner died */
ENOTRECOVERABLE = 98, /* State not recoverable */
ELAST = 98, /* Must equal largest errno */
}
EPERM :: Platform_Error.EPERM /* Operation not permitted */
ENOENT :: Platform_Error.ENOENT /* No such file or directory */
EINTR :: Platform_Error.EINTR /* Interrupted system call */
ESRCH :: Platform_Error.ESRCH /* No such process */
EIO :: Platform_Error.EIO /* Input/output error */
ENXIO :: Platform_Error.ENXIO /* Device not configured */
E2BIG :: Platform_Error.E2BIG /* Argument list too long */
ENOEXEC :: Platform_Error.ENOEXEC /* Exec format error */
EBADF :: Platform_Error.EBADF /* Bad file descriptor */
ECHILD :: Platform_Error.ECHILD /* No child processes */
EDEADLK :: Platform_Error.EDEADLK /* Resource deadlock avoided. 11 was EAGAIN */
ENOMEM :: Platform_Error.ENOMEM /* Cannot allocate memory */
EACCES :: Platform_Error.EACCES /* Permission denied */
EFAULT :: Platform_Error.EFAULT /* Bad address */
ENOTBLK :: Platform_Error.ENOTBLK /* Block device required */
EBUSY :: Platform_Error.EBUSY /* Device busy */
EEXIST :: Platform_Error.EEXIST /* File exists */
EXDEV :: Platform_Error.EXDEV /* Cross-device link */
ENODEV :: Platform_Error.ENODEV /* Operation not supported by device */
ENOTDIR :: Platform_Error.ENOTDIR /* Not a directory */
EISDIR :: Platform_Error.EISDIR /* Is a directory */
EINVAL :: Platform_Error.EINVAL /* Invalid argument */
ENFILE :: Platform_Error.ENFILE /* Too many open files in system */
EMFILE :: Platform_Error.EMFILE /* Too many open files */
ENOTTY :: Platform_Error.ENOTTY /* Inappropriate ioctl for device */
ETXTBSY :: Platform_Error.ETXTBSY /* Text file busy */
EFBIG :: Platform_Error.EFBIG /* File too large */
ENOSPC :: Platform_Error.ENOSPC /* No space left on device */
ESPIPE :: Platform_Error.ESPIPE /* Illegal seek */
EROFS :: Platform_Error.EROFS /* Read-only file system */
EMLINK :: Platform_Error.EMLINK /* Too many links */
EPIPE :: Platform_Error.EPIPE /* Broken pipe */
/* math software */
EDOM: Errno : 33 /* Numerical argument out of domain */
ERANGE: Errno : 34 /* Result too large or too small */
EDOM :: Platform_Error.EDOM /* Numerical argument out of domain */
ERANGE :: Platform_Error.ERANGE /* Result too large or too small */
/* non-blocking and interrupt i/o */
EAGAIN: Errno : 35 /* Resource temporarily unavailable */
EWOULDBLOCK: Errno : EAGAIN /* Operation would block */
EINPROGRESS: Errno : 36 /* Operation now in progress */
EALREADY: Errno : 37 /* Operation already in progress */
EAGAIN :: Platform_Error.EAGAIN /* Resource temporarily unavailable */
EWOULDBLOCK :: EAGAIN /* Operation would block */
EINPROGRESS :: Platform_Error.EINPROGRESS /* Operation now in progress */
EALREADY :: Platform_Error.EALREADY /* Operation already in progress */
/* ipc/network software -- argument errors */
ENOTSOCK: Errno : 38 /* Socket operation on non-socket */
EDESTADDRREQ: Errno : 39 /* Destination address required */
EMSGSIZE: Errno : 40 /* Message too long */
EPROTOTYPE: Errno : 41 /* Protocol wrong type for socket */
ENOPROTOOPT: Errno : 42 /* Protocol option not available */
EPROTONOSUPPORT: Errno : 43 /* Protocol not supported */
ESOCKTNOSUPPORT: Errno : 44 /* Socket type not supported */
EOPNOTSUPP: Errno : 45 /* Operation not supported */
EPFNOSUPPORT: Errno : 46 /* Protocol family not supported */
EAFNOSUPPORT: Errno : 47 /* Address family not supported by protocol family */
EADDRINUSE: Errno : 48 /* Address already in use */
EADDRNOTAVAIL: Errno : 49 /* Can't assign requested address */
ENOTSOCK :: Platform_Error.ENOTSOCK /* Socket operation on non-socket */
EDESTADDRREQ :: Platform_Error.EDESTADDRREQ /* Destination address required */
EMSGSIZE :: Platform_Error.EMSGSIZE /* Message too long */
EPROTOTYPE :: Platform_Error.EPROTOTYPE /* Protocol wrong type for socket */
ENOPROTOOPT :: Platform_Error.ENOPROTOOPT /* Protocol option not available */
EPROTONOSUPPORT :: Platform_Error.EPROTONOSUPPORT /* Protocol not supported */
ESOCKTNOSUPPORT :: Platform_Error.ESOCKTNOSUPPORT /* Socket type not supported */
EOPNOTSUPP :: Platform_Error.EOPNOTSUPP /* Operation not supported */
EPFNOSUPPORT :: Platform_Error.EPFNOSUPPORT /* Protocol family not supported */
EAFNOSUPPORT :: Platform_Error.EAFNOSUPPORT /* Address family not supported by protocol family */
EADDRINUSE :: Platform_Error.EADDRINUSE /* Address already in use */
EADDRNOTAVAIL :: Platform_Error.EADDRNOTAVAIL /* Can't assign requested address */
/* ipc/network software -- operational errors */
ENETDOWN: Errno : 50 /* Network is down */
ENETUNREACH: Errno : 51 /* Network is unreachable */
ENETRESET: Errno : 52 /* Network dropped connection on reset */
ECONNABORTED: Errno : 53 /* Software caused connection abort */
ECONNRESET: Errno : 54 /* Connection reset by peer */
ENOBUFS: Errno : 55 /* No buffer space available */
EISCONN: Errno : 56 /* Socket is already connected */
ENOTCONN: Errno : 57 /* Socket is not connected */
ESHUTDOWN: Errno : 58 /* Can't send after socket shutdown */
ETOOMANYREFS: Errno : 59 /* Too many references: can't splice */
ETIMEDOUT: Errno : 60 /* Operation timed out */
ECONNREFUSED: Errno : 61 /* Connection refused */
ENETDOWN :: Platform_Error.ENETDOWN /* Network is down */
ENETUNREACH :: Platform_Error.ENETUNREACH /* Network is unreachable */
ENETRESET :: Platform_Error.ENETRESET /* Network dropped connection on reset */
ECONNABORTED :: Platform_Error.ECONNABORTED /* Software caused connection abort */
ECONNRESET :: Platform_Error.ECONNRESET /* Connection reset by peer */
ENOBUFS :: Platform_Error.ENOBUFS /* No buffer space available */
EISCONN :: Platform_Error.EISCONN /* Socket is already connected */
ENOTCONN :: Platform_Error.ENOTCONN /* Socket is not connected */
ESHUTDOWN :: Platform_Error.ESHUTDOWN /* Can't send after socket shutdown */
ETOOMANYREFS :: Platform_Error.ETOOMANYREFS /* Too many references: can't splice */
ETIMEDOUT :: Platform_Error.ETIMEDOUT /* Operation timed out */
ECONNREFUSED :: Platform_Error.ECONNREFUSED /* Connection refused */
ELOOP: Errno : 62 /* Too many levels of symbolic links */
ENAMETOOLONG: Errno : 63 /* File name too long */
ELOOP :: Platform_Error.ELOOP /* Too many levels of symbolic links */
ENAMETOOLONG :: Platform_Error.ENAMETOOLONG /* File name too long */
/* should be rearranged */
EHOSTDOWN: Errno : 64 /* Host is down */
EHOSTUNREACH: Errno : 65 /* No route to host */
ENOTEMPTY: Errno : 66 /* Directory not empty */
EHOSTDOWN :: Platform_Error.EHOSTDOWN /* Host is down */
EHOSTUNREACH :: Platform_Error.EHOSTUNREACH /* No route to host */
ENOTEMPTY :: Platform_Error.ENOTEMPTY /* Directory not empty */
/* quotas & mush */
EPROCLIM: Errno : 67 /* Too many processes */
EUSERS: Errno : 68 /* Too many users */
EDQUOT: Errno : 69 /* Disc quota exceeded */
EPROCLIM :: Platform_Error.EPROCLIM /* Too many processes */
EUSERS :: Platform_Error.EUSERS /* Too many users */
EDQUOT :: Platform_Error.EDQUOT /* Disc quota exceeded */
/* Network File System */
ESTALE: Errno : 70 /* Stale NFS file handle */
EREMOTE: Errno : 71 /* Too many levels of remote in path */
EBADRPC: Errno : 72 /* RPC struct is bad */
ERPCMISMATCH: Errno : 73 /* RPC version wrong */
EPROGUNAVAIL: Errno : 74 /* RPC prog. not avail */
EPROGMISMATCH: Errno : 75 /* Program version wrong */
EPROCUNAVAIL: Errno : 76 /* Bad procedure for program */
ESTALE :: Platform_Error.ESTALE /* Stale NFS file handle */
EREMOTE :: Platform_Error.EREMOTE /* Too many levels of remote in path */
EBADRPC :: Platform_Error.EBADRPC /* RPC struct is bad */
ERPCMISMATCH :: Platform_Error.ERPCMISMATCH /* RPC version wrong */
EPROGUNAVAIL :: Platform_Error.EPROGUNAVAIL /* RPC prog. not avail */
EPROGMISMATCH :: Platform_Error.EPROGMISMATCH /* Program version wrong */
EPROCUNAVAIL :: Platform_Error.EPROCUNAVAIL /* Bad procedure for program */
ENOLCK: Errno : 77 /* No locks available */
ENOSYS: Errno : 78 /* Function not implemented */
ENOLCK :: Platform_Error.ENOLCK /* No locks available */
ENOSYS :: Platform_Error.ENOSYS /* Function not implemented */
EFTYPE: Errno : 79 /* Inappropriate file type or format */
EAUTH: Errno : 80 /* Authentication error */
ENEEDAUTH: Errno : 81 /* Need authenticator */
EFTYPE :: Platform_Error.EFTYPE /* Inappropriate file type or format */
EAUTH :: Platform_Error.EAUTH /* Authentication error */
ENEEDAUTH :: Platform_Error.ENEEDAUTH /* Need authenticator */
/* SystemV IPC */
EIDRM: Errno : 82 /* Identifier removed */
ENOMSG: Errno : 83 /* No message of desired type */
EOVERFLOW: Errno : 84 /* Value too large to be stored in data type */
EIDRM :: Platform_Error.EIDRM /* Identifier removed */
ENOMSG :: Platform_Error.ENOMSG /* No message of desired type */
EOVERFLOW :: Platform_Error.EOVERFLOW /* Value too large to be stored in data type */
/* Wide/multibyte-character handling, ISO/IEC 9899/AMD1:1995 */
EILSEQ: Errno : 85 /* Illegal byte sequence */
EILSEQ :: Platform_Error.EILSEQ /* Illegal byte sequence */
/* From IEEE Std 1003.1-2001 */
/* Base, Realtime, Threads or Thread Priority Scheduling option errors */
ENOTSUP: Errno : 86 /* Not supported */
ENOTSUP :: Platform_Error.ENOTSUP /* Not supported */
/* Realtime option errors */
ECANCELED: Errno : 87 /* Operation canceled */
ECANCELED :: Platform_Error.ECANCELED /* Operation canceled */
/* Realtime, XSI STREAMS option errors */
EBADMSG: Errno : 88 /* Bad or Corrupt message */
EBADMSG :: Platform_Error.EBADMSG /* Bad or Corrupt message */
/* XSI STREAMS option errors */
ENODATA: Errno : 89 /* No message available */
ENOSR: Errno : 90 /* No STREAM resources */
ENOSTR: Errno : 91 /* Not a STREAM */
ETIME: Errno : 92 /* STREAM ioctl timeout */
ENODATA :: Platform_Error.ENODATA /* No message available */
ENOSR :: Platform_Error.ENOSR /* No STREAM resources */
ENOSTR :: Platform_Error.ENOSTR /* Not a STREAM */
ETIME :: Platform_Error.ETIME /* STREAM ioctl timeout */
/* File system extended attribute errors */
ENOATTR: Errno : 93 /* Attribute not found */
ENOATTR :: Platform_Error.ENOATTR /* Attribute not found */
/* Realtime, XSI STREAMS option errors */
EMULTIHOP: Errno : 94 /* Multihop attempted */
ENOLINK: Errno : 95 /* Link has been severed */
EPROTO: Errno : 96 /* Protocol error */
EMULTIHOP :: Platform_Error.EMULTIHOP /* Multihop attempted */
ENOLINK :: Platform_Error.ENOLINK /* Link has been severed */
EPROTO :: Platform_Error.EPROTO /* Protocol error */
/* Robust mutexes */
EOWNERDEAD: Errno : 97 /* Previous owner died */
ENOTRECOVERABLE: Errno : 98 /* State not recoverable */
EOWNERDEAD :: Platform_Error.EOWNERDEAD /* Previous owner died */
ENOTRECOVERABLE :: Platform_Error.ENOTRECOVERABLE /* State not recoverable */
ELAST: Errno : 98 /* Must equal largest errno */
ELAST :: Platform_Error.ELAST /* Must equal largest errno */
/* end of errno */
@@ -338,8 +477,8 @@ is_path_separator :: proc(r: rune) -> bool {
return r == '/'
}
get_last_error :: proc "contextless" () -> int {
return int(__errno_location()^)
get_last_error :: proc "contextless" () -> Error {
return Error(__errno_location()^)
}
open :: proc(path: string, flags: int = O_RDONLY, mode: int = 0) -> (Handle, Errno) {