Skip to content

Commit 3e006f9

Browse files
Add missing POSIX Error code for WASI OS
1 parent 548c397 commit 3e006f9

File tree

2 files changed

+167
-3
lines changed

2 files changed

+167
-3
lines changed

stdlib/public/Platform/POSIXError.swift

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,168 @@ public enum POSIXErrorCode : Int32 {
556556
case EHWPOISON = 133
557557
}
558558

559+
#elseif os(WASI)
560+
561+
/// Enumeration describing POSIX error codes.
562+
public enum POSIXErrorCode : Int32 {
563+
/// Argument list too long.
564+
case E2BIG = 1
565+
/// Permission denied.
566+
case EACCES = 2
567+
/// Address in use.
568+
case EADDRINUSE = 3
569+
/// Address not available.
570+
case EADDRNOTAVAIL = 4
571+
/// Address family not supported.
572+
case EAFNOSUPPORT = 5
573+
/// Resource unavailable, or operation would block.
574+
case EAGAIN = 6
575+
/// Operation would block.
576+
public static var EWOULDBLOCK: POSIXErrorCode { return .EAGAIN }
577+
/// Connection already in progress.
578+
case EALREADY = 7
579+
/// Bad file descriptor.
580+
case EBADF = 8
581+
/// Bad message.
582+
case EBADMSG = 9
583+
/// Device or resource busy.
584+
case EBUSY = 10
585+
/// Operation canceled.
586+
case ECANCELED = 11
587+
/// No child processes.
588+
case ECHILD = 12
589+
/// Connection aborted.
590+
case ECONNABORTED = 13
591+
/// Connection refused.
592+
case ECONNREFUSED = 14
593+
/// Connection reset.
594+
case ECONNRESET = 15
595+
/// Resource deadlock would occur.
596+
case EDEADLK = 16
597+
/// Destination address required.
598+
case EDESTADDRREQ = 17
599+
/// Mathematics argument out of domain of function.
600+
case EDOM = 18
601+
/// Reserved.
602+
case EDQUOT = 19
603+
/// File exists.
604+
case EEXIST = 20
605+
/// Bad address.
606+
case EFAULT = 21
607+
/// File too large.
608+
case EFBIG = 22
609+
/// Host is unreachable.
610+
case EHOSTUNREACH = 23
611+
/// Identifier removed.
612+
case EIDRM = 24
613+
/// Illegal byte sequence.
614+
case EILSEQ = 25
615+
/// Operation in progress.
616+
case EINPROGRESS = 26
617+
/// Interrupted function.
618+
case EINTR = 27
619+
/// Invalid argument.
620+
case EINVAL = 28
621+
/// I/O error.
622+
case EIO = 29
623+
/// Socket is connected.
624+
case EISCONN = 30
625+
/// Is a directory.
626+
case EISDIR = 31
627+
/// Too many levels of symbolic links.
628+
case ELOOP = 32
629+
/// File descriptor value too large.
630+
case EMFILE = 33
631+
/// Too many links.
632+
case EMLINK = 34
633+
/// Message too large.
634+
case EMSGSIZE = 35
635+
/// Reserved.
636+
case EMULTIHOP = 36
637+
/// Filename too long.
638+
case ENAMETOOLONG = 37
639+
/// Network is down.
640+
case ENETDOWN = 38
641+
/// Connection aborted by network.
642+
case ENETRESET = 39
643+
/// Network unreachable.
644+
case ENETUNREACH = 40
645+
/// Too many files open in system.
646+
case ENFILE = 41
647+
/// No buffer space available.
648+
case ENOBUFS = 42
649+
/// No such device.
650+
case ENODEV = 43
651+
/// No such file or directory.
652+
case ENOENT = 44
653+
/// Executable file format error.
654+
case ENOEXEC = 45
655+
/// No locks available.
656+
case ENOLCK = 46
657+
/// Reserved.
658+
case ENOLINK = 47
659+
/// Not enough space.
660+
case ENOMEM = 48
661+
/// No message of the desired type.
662+
case ENOMSG = 49
663+
/// Protocol not available.
664+
case ENOPROTOOPT = 50
665+
/// No space left on device.
666+
case ENOSPC = 51
667+
/// Function not supported.
668+
case ENOSYS = 52
669+
/// The socket is not connected.
670+
case ENOTCONN = 53
671+
/// Not a directory or a symbolic link to a directory.
672+
case ENOTDIR = 54
673+
/// Directory not empty.
674+
case ENOTEMPTY = 55
675+
/// State not recoverable.
676+
case ENOTRECOVERABLE = 56
677+
/// Not a socket.
678+
case ENOTSOCK = 57
679+
/// Not supported, or operation not supported on socket.
680+
case ENOTSUP = 58
681+
/// Operation not supported on transport endpoint
682+
public static var EOPNOTSUPP: POSIXErrorCode { return .ENOTSUP }
683+
/// Inappropriate I/O control operation.
684+
case ENOTTY = 59
685+
/// No such device or address.
686+
case ENXIO = 60
687+
/// Value too large to be stored in data type.
688+
case EOVERFLOW = 61
689+
/// Previous owner died.
690+
case EOWNERDEAD = 62
691+
/// Operation not permitted.
692+
case EPERM = 63
693+
/// Broken pipe.
694+
case EPIPE = 64
695+
/// Protocol error.
696+
case EPROTO = 65
697+
/// Protocol not supported.
698+
case EPROTONOSUPPORT = 66
699+
/// Protocol wrong type for socket.
700+
case EPROTOTYPE = 67
701+
/// Result too large.
702+
case ERANGE = 68
703+
/// Read-only file system.
704+
case EROFS = 69
705+
/// Invalid seek.
706+
case ESPIPE = 70
707+
/// No such process.
708+
case ESRCH = 71
709+
/// Reserved.
710+
case ESTALE = 72
711+
/// Connection timed out.
712+
case ETIMEDOUT = 73
713+
/// Text file busy.
714+
case ETXTBSY = 74
715+
/// Cross-device link.
716+
case EXDEV = 75
717+
/// Extension: Capabilities insufficient.
718+
case ENOTCAPABLE = 76
719+
}
720+
559721
#elseif os(Windows)
560722

561723
/// Enumeration describing POSIX error codes.

stdlib/public/Platform/WASI.swift.gyb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude
6464

6565
public let MAP_FAILED: UnsafeMutableRawPointer! = UnsafeMutableRawPointer(bitPattern: -1)
6666

67-
// WebAssembly's error.h uses a macro that Swift can't import.
68-
public let EINTR:Int32 = 27
69-
public let EINVAL:Int32 = 28
67+
// wasi-libc's error.h uses a macro that Swift can't import.
68+
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINTR'.")
69+
public let EINTR: Int32 = 27
70+
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINVAL'.")
71+
public let EINVAL: Int32 = 28

0 commit comments

Comments
 (0)