# Generated by tools/gen_errorcodes.nim. DO NOT EDIT!

when not defined(nimony):
  import errorcodes

var EOVERFLOW {.importc: "EOVERFLOW", header: "<errno.h>".}: int32
var ERANGE {.importc: "ERANGE", header: "<errno.h>".}: int32
var EDOM {.importc: "EDOM", header: "<errno.h>".}: int32
var ENOMEM {.importc: "ENOMEM", header: "<errno.h>".}: int32
var ENOSPC {.importc: "ENOSPC", header: "<errno.h>".}: int32
var EIO {.importc: "EIO", header: "<errno.h>".}: int32
var EINVAL {.importc: "EINVAL", header: "<errno.h>".}: int32
var EBADMSG {.importc: "EBADMSG", header: "<errno.h>".}: int32
var EILSEQ {.importc: "EILSEQ", header: "<errno.h>".}: int32
var ENOMSG {.importc: "ENOMSG", header: "<errno.h>".}: int32
var EDESTADDRREQ {.importc: "EDESTADDRREQ", header: "<errno.h>".}: int32
var E2BIG {.importc: "E2BIG", header: "<errno.h>".}: int32
var ENOBUFS {.importc: "ENOBUFS", header: "<errno.h>".}: int32
var ENODATA {.importc: "ENODATA", header: "<errno.h>".}: int32
var EBUSY {.importc: "EBUSY", header: "<errno.h>".}: int32
var ETXTBSY {.importc: "ETXTBSY", header: "<errno.h>".}: int32
var ECHILD {.importc: "ECHILD", header: "<errno.h>".}: int32
var EOWNERDEAD {.importc: "EOWNERDEAD", header: "<errno.h>".}: int32
var ENOLCK {.importc: "ENOLCK", header: "<errno.h>".}: int32
var ENFILE {.importc: "ENFILE", header: "<errno.h>".}: int32
var EACCES {.importc: "EACCES", header: "<errno.h>".}: int32
var EPERM {.importc: "EPERM", header: "<errno.h>".}: int32
var EAGAIN {.importc: "EAGAIN", header: "<errno.h>".}: int32
var EWOULDBLOCK {.importc: "EWOULDBLOCK", header: "<errno.h>".}: int32
var ETIMEDOUT {.importc: "ETIMEDOUT", header: "<errno.h>".}: int32
var ETIME {.importc: "ETIME", header: "<errno.h>".}: int32
var EINTR {.importc: "EINTR", header: "<errno.h>".}: int32
var EDEADLK {.importc: "EDEADLK", header: "<errno.h>".}: int32
var EADDRINUSE {.importc: "EADDRINUSE", header: "<errno.h>".}: int32
var EISCONN {.importc: "EISCONN", header: "<errno.h>".}: int32
var EADDRNOTAVAIL {.importc: "EADDRNOTAVAIL", header: "<errno.h>".}: int32
var EAFNOSUPPORT {.importc: "EAFNOSUPPORT", header: "<errno.h>".}: int32
var EOPNOTSUPP {.importc: "EOPNOTSUPP", header: "<errno.h>".}: int32
var ENOTSUP {.importc: "ENOTSUP", header: "<errno.h>".}: int32
var ENOSYS {.importc: "ENOSYS", header: "<errno.h>".}: int32
var EPROTONOSUPPORT {.importc: "EPROTONOSUPPORT", header: "<errno.h>".}: int32
var ENOTTY {.importc: "ENOTTY", header: "<errno.h>".}: int32
var ESPIPE {.importc: "ESPIPE", header: "<errno.h>".}: int32
var EISDIR {.importc: "EISDIR", header: "<errno.h>".}: int32
var ENOTEMPTY {.importc: "ENOTEMPTY", header: "<errno.h>".}: int32
var ECANCELED {.importc: "ECANCELED", header: "<errno.h>".}: int32
var ECONNABORTED {.importc: "ECONNABORTED", header: "<errno.h>".}: int32
var ENETRESET {.importc: "ENETRESET", header: "<errno.h>".}: int32
var EALREADY {.importc: "EALREADY", header: "<errno.h>".}: int32
var EINPROGRESS {.importc: "EINPROGRESS", header: "<errno.h>".}: int32
var ENAMETOOLONG {.importc: "ENAMETOOLONG", header: "<errno.h>".}: int32
var EEXIST {.importc: "EEXIST", header: "<errno.h>".}: int32
var ENOENT {.importc: "ENOENT", header: "<errno.h>".}: int32
var EIDRM {.importc: "EIDRM", header: "<errno.h>".}: int32
var ENODEV {.importc: "ENODEV", header: "<errno.h>".}: int32
var ENOTDIR {.importc: "ENOTDIR", header: "<errno.h>".}: int32
var EFBIG {.importc: "EFBIG", header: "<errno.h>".}: int32
var EMSGSIZE {.importc: "EMSGSIZE", header: "<errno.h>".}: int32
var EPIPE {.importc: "EPIPE", header: "<errno.h>".}: int32
var EBADF {.importc: "EBADF", header: "<errno.h>".}: int32
var EMFILE {.importc: "EMFILE", header: "<errno.h>".}: int32
var ENOSTR {.importc: "ENOSTR", header: "<errno.h>".}: int32
var ENOTSOCK {.importc: "ENOTSOCK", header: "<errno.h>".}: int32
var ENOSR {.importc: "ENOSR", header: "<errno.h>".}: int32
var ENXIO {.importc: "ENXIO", header: "<errno.h>".}: int32
var ESRCH {.importc: "ESRCH", header: "<errno.h>".}: int32
var ENOEXEC {.importc: "ENOEXEC", header: "<errno.h>".}: int32
var ELOOP {.importc: "ELOOP", header: "<errno.h>".}: int32
var EMLINK {.importc: "EMLINK", header: "<errno.h>".}: int32
var EXDEV {.importc: "EXDEV", header: "<errno.h>".}: int32
var EPROTOTYPE {.importc: "EPROTOTYPE", header: "<errno.h>".}: int32
var ENOPROTOOPT {.importc: "ENOPROTOOPT", header: "<errno.h>".}: int32
var EPROTO {.importc: "EPROTO", header: "<errno.h>".}: int32
var EROFS {.importc: "EROFS", header: "<errno.h>".}: int32
var EFAULT {.importc: "EFAULT", header: "<errno.h>".}: int32
var ENETDOWN {.importc: "ENETDOWN", header: "<errno.h>".}: int32
var ENETUNREACH {.importc: "ENETUNREACH", header: "<errno.h>".}: int32
var ECONNRESET {.importc: "ECONNRESET", header: "<errno.h>".}: int32
var ENOTCONN {.importc: "ENOTCONN", header: "<errno.h>".}: int32
var ECONNREFUSED {.importc: "ECONNREFUSED", header: "<errno.h>".}: int32
var EHOSTUNREACH {.importc: "EHOSTUNREACH", header: "<errno.h>".}: int32
var ENOTRECOVERABLE {.importc: "ENOTRECOVERABLE", header: "<errno.h>".}: int32


proc posixToErrorCode*(err: int32): ErrorCode =
  if err == 0'i32:
    Success
  elif err == EOVERFLOW:
    OverflowError
  elif err == ERANGE or err == EDOM:
    RangeError
  elif err == ENOMEM:
    OutOfMemError
  elif err == ENOSPC:
    DiskFullError
  elif err == EIO:
    IOError
  elif err == EINVAL or err == EBADMSG or err == EILSEQ or err == ENOMSG or err == EDESTADDRREQ:
    ValueError
  elif err == E2BIG or err == ENOBUFS:
    FullError
  elif err == ENODATA:
    EmptyError
  elif err == EBUSY or err == ETXTBSY:
    BusyError
  elif err == ECHILD or err == EOWNERDEAD:
    DeadResource
  elif err == ENOLCK:
    ResourceExhaustedError
  elif err == ENFILE:
    DescriptorExhaustedError
  elif err == EACCES or err == EPERM:
    PermissionDenied
  elif err == EAGAIN or err == EWOULDBLOCK:
    RetryError
  elif err == ETIMEDOUT or err == ETIME:
    TimeoutError
  elif err == EINTR:
    InterruptedError
  elif err == EDEADLK:
    DeadlockError
  elif err == EADDRINUSE or err == EISCONN:
    AlreadyConnected
  elif err == EADDRNOTAVAIL:
    AddressNotAvailable
  elif err == EAFNOSUPPORT:
    AddressFamilyUnsupported
  elif err == EOPNOTSUPP or err == ENOTSUP or err == ENOSYS or err == EPROTONOSUPPORT or err == ENOTTY or err == ESPIPE or err == EISDIR or err == ENOTEMPTY:
    BadOperation
  elif err == ECANCELED or err == ECONNABORTED or err == ENETRESET:
    AbortedOperation
  elif err == EALREADY or err == EINPROGRESS:
    AlreadyInProgress
  elif err == ENAMETOOLONG:
    NameTooLong
  elif err == EEXIST:
    NameExists
  elif err == ENOENT or err == EIDRM or err == ENODEV or err == ENOTDIR:
    NameNotFound
  elif err == EFBIG or err == EMSGSIZE:
    ContentTooLong
  elif err == EPIPE or err == EBADF or err == EMFILE or err == ENOSTR or err == ENOTSOCK or err == ENOSR or err == ENXIO or err == ESRCH:
    BadDescriptor
  elif err == ENOEXEC:
    BadExecutable
  elif err == ELOOP or err == EMLINK or err == EXDEV:
    BadLink
  elif err == EPROTOTYPE or err == ENOPROTOOPT:
    BadProtocol
  elif err == EPROTO:
    ProtocolError
  elif err == EROFS:
    ReadonlyProtection
  elif err == EFAULT:
    SegFault
  elif err == ENETDOWN or err == ENETUNREACH or err == ECONNRESET or err == ENOTCONN:
    Disconnected
  elif err == ECONNREFUSED:
    RefusedConnection
  elif err == EHOSTUNREACH:
    UnreachableHost
  elif err == ENOTRECOVERABLE:
    UnrecoverableState
  else:
    Failure

proc errorCodeToPosix*(err: ErrorCode): int32 =
  case err
  of Success: 0'i32
  of OverflowError: EOVERFLOW
  of RangeError: ERANGE
  of OutOfMemError: ENOMEM
  of DiskFullError: ENOSPC
  of IOError: EIO
  of ValueError: EINVAL
  of FullError: E2BIG
  of EmptyError: ENODATA
  of BusyError: EBUSY
  of DeadResource: ECHILD
  of ResourceExhaustedError: ENOLCK
  of DescriptorExhaustedError: ENFILE
  of PermissionDenied: EACCES
  of RetryError: EAGAIN
  of TimeoutError: ETIMEDOUT
  of InterruptedError: EINTR
  of DeadlockError: EDEADLK
  of AlreadyConnected: EADDRINUSE
  of AddressNotAvailable: EADDRNOTAVAIL
  of AddressFamilyUnsupported: EAFNOSUPPORT
  of BadOperation: EOPNOTSUPP
  of AbortedOperation: ECANCELED
  of AlreadyInProgress: EALREADY
  of NameTooLong: ENAMETOOLONG
  of NameExists: EEXIST
  of NameNotFound: ENOENT
  of ContentTooLong: EFBIG
  of BadDescriptor: EPIPE
  of BadExecutable: ENOEXEC
  of BadLink: ELOOP
  of BadProtocol: EPROTOTYPE
  of ProtocolError: EPROTO
  of ReadonlyProtection: EROFS
  of SegFault: EFAULT
  of Disconnected: ENETDOWN
  of RefusedConnection: ECONNREFUSED
  of UnreachableHost: EHOSTUNREACH
  of UnrecoverableState: ENOTRECOVERABLE
  else: 1'i32
