Skip to content

Commit 0582890

Browse files
Merge pull request #5509 from swiftwasm/katei/improve-wasi-libc-overlay
[wasm] Add more errno support in WASILibc overlay
2 parents d7950b4 + d45bb82 commit 0582890

File tree

1 file changed

+92
-29
lines changed

1 file changed

+92
-29
lines changed

stdlib/public/Platform/WASILibc.swift.gyb

Lines changed: 92 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,98 @@ public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude
6464

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

67-
// wasi-libc's error.h uses a macro that Swift can't import.
68-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EACCES'.")
69-
public let EACCES: Int32 = 2
70-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EDQUOT'.")
71-
public let EDQUOT: Int32 = 19
72-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EEXIST'.")
73-
public let EEXIST: Int32 = 20
74-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EFBIG'.")
75-
public let EFBIG: Int32 = 22
76-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINTR'.")
77-
public let EINTR: Int32 = 27
78-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINVAL'.")
79-
public let EINVAL: Int32 = 28
80-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.ENAMETOOLONG'.")
81-
public let ENAMETOOLONG: Int32 = 37
82-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.ENOENT'.")
83-
public let ENOENT: Int32 = 44
84-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.ENOSPC'.")
85-
public let ENOSPC: Int32 = 51
86-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EPERM'.")
87-
public let EPERM: Int32 = 63
88-
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EROFS'.")
89-
public let EROFS: Int32 = 69
90-
91-
92-
// wasi-libc's _seek.h uses a macro that Swift can't import.
93-
// https://developer.apple.com/documentation/swift/using-imported-c-macros-in-swift
94-
// https://github.com/apple/swift/blob/c55b9cc87925c5d63a21d383ad23dff056d36607/lib/ClangImporter/ImportName.cpp#L2115-L2117
95-
// https://github.com/WebAssembly/wasi-libc/pull/148
67+
// TODO: wasi-libc's error.h defines these macros as function-like macros, which
68+
// Swift can't import for now.
69+
%{
70+
posix_error_codes = [
71+
"E2BIG",
72+
"EACCES",
73+
"EADDRINUSE",
74+
"EADDRNOTAVAIL",
75+
"EAFNOSUPPORT",
76+
"EAGAIN",
77+
"EALREADY",
78+
"EBADF",
79+
"EBADMSG",
80+
"EBUSY",
81+
"ECANCELED",
82+
"ECHILD",
83+
"ECONNABORTED",
84+
"ECONNREFUSED",
85+
"ECONNRESET",
86+
"EDEADLK",
87+
"EDESTADDRREQ",
88+
"EDOM",
89+
"EDQUOT",
90+
"EEXIST",
91+
"EFAULT",
92+
"EFBIG",
93+
"EHOSTUNREACH",
94+
"EIDRM",
95+
"EILSEQ",
96+
"EINPROGRESS",
97+
"EINTR",
98+
"EINVAL",
99+
"EIO",
100+
"EISCONN",
101+
"EISDIR",
102+
"ELOOP",
103+
"EMFILE",
104+
"EMLINK",
105+
"EMSGSIZE",
106+
"EMULTIHOP",
107+
"ENAMETOOLONG",
108+
"ENETDOWN",
109+
"ENETRESET",
110+
"ENETUNREACH",
111+
"ENFILE",
112+
"ENOBUFS",
113+
"ENODEV",
114+
"ENOENT",
115+
"ENOEXEC",
116+
"ENOLCK",
117+
"ENOLINK",
118+
"ENOMEM",
119+
"ENOMSG",
120+
"ENOPROTOOPT",
121+
"ENOSPC",
122+
"ENOSYS",
123+
"ENOTCONN",
124+
"ENOTDIR",
125+
"ENOTEMPTY",
126+
"ENOTRECOVERABLE",
127+
"ENOTSOCK",
128+
"ENOTSUP",
129+
"ENOTTY",
130+
"ENXIO",
131+
"EOVERFLOW",
132+
"EOWNERDEAD",
133+
"EPERM",
134+
"EPIPE",
135+
"EPROTO",
136+
"EPROTONOSUPPORT",
137+
"EPROTOTYPE",
138+
"ERANGE",
139+
"EROFS",
140+
"ESPIPE",
141+
"ESRCH",
142+
"ESTALE",
143+
"ETIMEDOUT",
144+
"ETXTBSY",
145+
"EXDEV",
146+
"ENOTCAPABLE",
147+
]
148+
}%
149+
150+
%for ecode in posix_error_codes:
151+
152+
@available(*, deprecated, message: "Please use 'POSIXErrorCode.${ecode}'.")
153+
public let ${ecode} = POSIXErrorCode.${ecode}.rawValue
154+
155+
%end
156+
157+
// TODO: wasi-libc's _seek.h defines these macros as function-like macros, which
158+
// Swift can't import for now.
96159
public let SEEK_SET: Int32 = 0
97160
public let SEEK_CUR: Int32 = 1
98161
public let SEEK_END: Int32 = 2

0 commit comments

Comments
 (0)