Skip to content

Commit f34e321

Browse files
authored
WebAssembly: add WASI cases to POSIXErrorCode enum (swiftlang#39482)
These new cases match WASI-libc declarations at https://github.com/WebAssembly/wasi-libc/blob/ad513341/libc-bottom-half/headers/public/wasi/api.h#L106
1 parent 4521c99 commit f34e321

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

stdlib/public/Platform/POSIXError.swift

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

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

561729
/// Enumeration describing POSIX error codes.

0 commit comments

Comments
 (0)