Skip to content

Commit a77f161

Browse files
authored
Merge pull request #38341 from 3405691582/FoundationInterop
2 parents cee89ec + ac9640b commit a77f161

File tree

3 files changed

+312
-1
lines changed

3 files changed

+312
-1
lines changed

stdlib/public/Platform/POSIXError.swift

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,4 +850,202 @@ public enum POSIXErrorCode : Int32 {
850850
case STRUNCATE = 80
851851
}
852852

853+
#elseif os(OpenBSD)
854+
855+
/// Enumeration describing POSIX error codes.
856+
public enum POSIXErrorCode : Int32 {
857+
/// Operation not permitted
858+
case EPERM = 1
859+
/// No such file or directory
860+
case ENOENT = 2
861+
/// No such process
862+
case ESRCH = 3
863+
/// Interrupted system call
864+
case EINTR = 4
865+
/// Input/output error
866+
case EIO = 5
867+
/// Device not configured
868+
case ENXIO = 6
869+
/// Argument list too long
870+
case E2BIG = 7
871+
/// Exec format error
872+
case ENOEXEC = 8
873+
/// Bad file descriptor
874+
case EBADF = 9
875+
/// No child processes
876+
case ECHILD = 10
877+
/// Resource deadlock avoided
878+
case EDEADLK = 11
879+
/// Cannot allocate memory
880+
case ENOMEM = 12
881+
/// Permission denied
882+
case EACCES = 13
883+
/// Bad address
884+
case EFAULT = 14
885+
/// Block device required
886+
case ENOTBLK = 15
887+
/// Device busy
888+
case EBUSY = 16
889+
/// File exists
890+
case EEXIST = 17
891+
/// Cross-device link
892+
case EXDEV = 18
893+
/// Operation not supported by device
894+
case ENODEV = 19
895+
/// Not a directory
896+
case ENOTDIR = 20
897+
/// Is a directory
898+
case EISDIR = 21
899+
/// Invalid argument
900+
case EINVAL = 22
901+
/// Too many open files in system
902+
case ENFILE = 23
903+
/// Too many open files
904+
case EMFILE = 24
905+
/// Inappropriate ioctl for device
906+
case ENOTTY = 25
907+
/// Text file busy
908+
case ETXTBSY = 26
909+
/// File too large
910+
case EFBIG = 27
911+
/// No space left on device
912+
case ENOSPC = 28
913+
/// Illegal seek
914+
case ESPIPE = 29
915+
/// Read-only file system
916+
case EROFS = 30
917+
/// Too many links
918+
case EMLINK = 31
919+
/// Broken pipe
920+
case EPIPE = 32
921+
/// Numerical argument out of domain
922+
case EDOM = 33
923+
/// Result too large
924+
case ERANGE = 34
925+
/// Resource temporarily unavailable
926+
case EAGAIN = 35
927+
/// Operation would block
928+
public static var EWOULDBLOCK: POSIXErrorCode { return .EAGAIN }
929+
/// Operation now in progress
930+
case EINPROGRESS = 36
931+
/// Operation already in progress
932+
case EALREADY = 37
933+
/// Socket operation on non-socket
934+
case ENOTSOCK = 38
935+
/// Destination address required
936+
case EDESTADDRREQ = 39
937+
/// Message too long
938+
case EMSGSIZE = 40
939+
/// Protocol wrong type for socket
940+
case EPROTOTYPE = 41
941+
/// Protocol not available
942+
case ENOPROTOOPT = 42
943+
/// Protocol not supported
944+
case EPROTONOSUPPORT = 43
945+
/// Socket type not supported
946+
case ESOCKTNOSUPPORT = 44
947+
/// Operation not supported
948+
case EOPNOTSUPP = 45
949+
/// Protocol family not supported
950+
case EPFNOSUPPORT = 46
951+
/// Address family not supported by protocol family
952+
case EAFNOSUPPORT = 47
953+
/// Address already in use
954+
case EADDRINUSE = 48
955+
/// Can't assign requested address
956+
case EADDRNOTAVAIL = 49
957+
/// Network is down
958+
case ENETDOWN = 50
959+
/// Network is unreachable
960+
case ENETUNREACH = 51
961+
/// Network dropped connection on reset
962+
case ENETRESET = 52
963+
/// Software caused connection abort
964+
case ECONNABORTED = 53
965+
/// Connection reset by peer
966+
case ECONNRESET = 54
967+
/// No buffer space available
968+
case ENOBUFS = 55
969+
/// Socket is already connected
970+
case EISCONN = 56
971+
/// Socket is not connected
972+
case ENOTCONN = 57
973+
/// Can't send after socket shutdown
974+
case ESHUTDOWN = 58
975+
/// Too many references: can't splice
976+
case ETOOMANYREFS = 59
977+
/// Operation timed out
978+
case ETIMEDOUT = 60
979+
/// Connection refused
980+
case ECONNREFUSED = 61
981+
/// Too many levels of symbolic links
982+
case ELOOP = 62
983+
/// File name too long
984+
case ENAMETOOLONG = 63
985+
/// Host is down
986+
case EHOSTDOWN = 64
987+
/// No route to host
988+
case EHOSTUNREACH = 65
989+
/// Directory not empty
990+
case ENOTEMPTY = 66
991+
/// Too many processes
992+
case EPROCLIM = 67
993+
/// Too many users
994+
case EUSERS = 68
995+
/// Disk quota exceeded
996+
case EDQUOT = 69
997+
/// Stale NFS file handle
998+
case ESTALE = 70
999+
/// Too many levels of remote in path
1000+
case EREMOTE = 71
1001+
/// RPC struct is bad
1002+
case EBADRPC = 72
1003+
/// RPC version wrong
1004+
case ERPCMISMATCH = 73
1005+
/// RPC program not available
1006+
case EPROGUNAVAIL = 74
1007+
/// Program version wrong
1008+
case EPROGMISMATCH = 75
1009+
/// Bad procedure for program
1010+
case EPROCUNAVAIL = 76
1011+
/// No locks available
1012+
case ENOLCK = 77
1013+
/// Function not implemented
1014+
case ENOSYS = 78
1015+
/// Inappropriate file type or format
1016+
case EFTYPE = 79
1017+
/// Authentication error
1018+
case EAUTH = 80
1019+
/// Need authenticator
1020+
case ENEEDAUTH = 81
1021+
/// IPsec processing failure
1022+
case EIPSEC = 82
1023+
/// Attribute not found
1024+
case ENOATTR = 83
1025+
/// Illegal byte sequence
1026+
case EILSEQ = 84
1027+
/// No medium found
1028+
case ENOMEDIUM = 85
1029+
/// Wrong medium type
1030+
case EMEDIUMTYPE = 86
1031+
/// Value too large to be stored in data type
1032+
case EOVERFLOW = 87
1033+
/// Operation canceled
1034+
case ECANCELED = 88
1035+
/// Identifier removed
1036+
case EIDRM = 89
1037+
/// No message of desired type
1038+
case ENOMSG = 90
1039+
/// Not supported
1040+
case ENOTSUP = 91
1041+
/// Bad message
1042+
case EBADMSG = 92
1043+
/// State not recoverable
1044+
case ENOTRECOVERABLE = 93
1045+
/// Previous owner died
1046+
case EOWNERDEAD = 94
1047+
/// Protocol error
1048+
case EPROTO = 95
1049+
}
1050+
8531051
#endif

stdlib/public/Platform/libc-openbsd.modulemap.gyb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,18 @@ module SwiftGlibc [system] {
7272
header "${GLIBC_INCLUDE_PATH}/string.h"
7373
export *
7474
}
75+
module sysexits {
76+
header "${GLIBC_INCLUDE_PATH}/sysexits.h"
77+
export *
78+
}
7579
module time {
7680
header "${GLIBC_INCLUDE_PATH}/time.h"
7781
export *
7882
}
83+
module util {
84+
header "${GLIBC_INCLUDE_PATH}/util.h"
85+
export *
86+
}
7987
}
8088

8189
// POSIX
@@ -241,6 +249,10 @@ module SwiftGlibc [system] {
241249
header "${GLIBC_ARCH_INCLUDE_PATH}/sys/mman.h"
242250
export *
243251
}
252+
module mount {
253+
header "${GLIBC_ARCH_INCLUDE_PATH}/sys/mount.h"
254+
export *
255+
}
244256
module msg {
245257
header "${GLIBC_ARCH_INCLUDE_PATH}/sys/msg.h"
246258
export *

validation-test/stdlib/POSIXErrorCode.swift

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-run-simple-swift
22
// REQUIRES: executable_test
3-
// REQUIRES: VENDOR=apple || OS=linux-androideabi || OS=linux-android || OS=linux-gnu
3+
// REQUIRES: VENDOR=apple || OS=linux-androideabi || OS=linux-android || OS=linux-gnu || OS=openbsd
44
// UNSUPPORTED: freestanding
55

66
import Swift
@@ -156,6 +156,107 @@ POSIXErrorCodeTestSuite.test("Linux POSIX error codes constants") {
156156
expectEqual(EOWNERDEAD, POSIXErrorCode.EOWNERDEAD.rawValue)
157157
expectEqual(ENOTRECOVERABLE, POSIXErrorCode.ENOTRECOVERABLE.rawValue)
158158
}
159+
#elseif os(OpenBSD)
160+
161+
POSIXErrorCodeTestSuite.test("OpenBSD POSIX error codes constants") {
162+
expectEqual(EPERM, POSIXErrorCode.EPERM.rawValue)
163+
expectEqual(ENOENT, POSIXErrorCode.ENOENT.rawValue)
164+
expectEqual(ESRCH, POSIXErrorCode.ESRCH.rawValue)
165+
expectEqual(EINTR, POSIXErrorCode.EINTR.rawValue)
166+
expectEqual(EIO, POSIXErrorCode.EIO.rawValue)
167+
expectEqual(ENXIO, POSIXErrorCode.ENXIO.rawValue)
168+
expectEqual(E2BIG, POSIXErrorCode.E2BIG.rawValue)
169+
expectEqual(ENOEXEC, POSIXErrorCode.ENOEXEC.rawValue)
170+
expectEqual(EBADF, POSIXErrorCode.EBADF.rawValue)
171+
expectEqual(ECHILD, POSIXErrorCode.ECHILD.rawValue)
172+
expectEqual(EDEADLK, POSIXErrorCode.EDEADLK.rawValue)
173+
expectEqual(ENOMEM, POSIXErrorCode.ENOMEM.rawValue)
174+
expectEqual(EACCES, POSIXErrorCode.EACCES.rawValue)
175+
expectEqual(EFAULT, POSIXErrorCode.EFAULT.rawValue)
176+
expectEqual(ENOTBLK, POSIXErrorCode.ENOTBLK.rawValue)
177+
expectEqual(EBUSY, POSIXErrorCode.EBUSY.rawValue)
178+
expectEqual(EEXIST, POSIXErrorCode.EEXIST.rawValue)
179+
expectEqual(EXDEV, POSIXErrorCode.EXDEV.rawValue)
180+
expectEqual(ENODEV, POSIXErrorCode.ENODEV.rawValue)
181+
expectEqual(ENOTDIR, POSIXErrorCode.ENOTDIR.rawValue)
182+
expectEqual(EISDIR, POSIXErrorCode.EISDIR.rawValue)
183+
expectEqual(EINVAL, POSIXErrorCode.EINVAL.rawValue)
184+
expectEqual(ENFILE, POSIXErrorCode.ENFILE.rawValue)
185+
expectEqual(EMFILE, POSIXErrorCode.EMFILE.rawValue)
186+
expectEqual(ENOTTY, POSIXErrorCode.ENOTTY.rawValue)
187+
expectEqual(ETXTBSY, POSIXErrorCode.ETXTBSY.rawValue)
188+
expectEqual(EFBIG, POSIXErrorCode.EFBIG.rawValue)
189+
expectEqual(ENOSPC, POSIXErrorCode.ENOSPC.rawValue)
190+
expectEqual(ESPIPE, POSIXErrorCode.ESPIPE.rawValue)
191+
expectEqual(EROFS, POSIXErrorCode.EROFS.rawValue)
192+
expectEqual(EMLINK, POSIXErrorCode.EMLINK.rawValue)
193+
expectEqual(EPIPE, POSIXErrorCode.EPIPE.rawValue)
194+
expectEqual(EDOM, POSIXErrorCode.EDOM.rawValue)
195+
expectEqual(ERANGE, POSIXErrorCode.ERANGE.rawValue)
196+
expectEqual(EAGAIN, POSIXErrorCode.EAGAIN.rawValue)
197+
expectEqual(EINPROGRESS, POSIXErrorCode.EINPROGRESS.rawValue)
198+
expectEqual(EALREADY, POSIXErrorCode.EALREADY.rawValue)
199+
expectEqual(ENOTSOCK, POSIXErrorCode.ENOTSOCK.rawValue)
200+
expectEqual(EDESTADDRREQ, POSIXErrorCode.EDESTADDRREQ.rawValue)
201+
expectEqual(EMSGSIZE, POSIXErrorCode.EMSGSIZE.rawValue)
202+
expectEqual(EPROTOTYPE, POSIXErrorCode.EPROTOTYPE.rawValue)
203+
expectEqual(ENOPROTOOPT, POSIXErrorCode.ENOPROTOOPT.rawValue)
204+
expectEqual(EPROTONOSUPPORT, POSIXErrorCode.EPROTONOSUPPORT.rawValue)
205+
expectEqual(ESOCKTNOSUPPORT, POSIXErrorCode.ESOCKTNOSUPPORT.rawValue)
206+
expectEqual(EOPNOTSUPP, POSIXErrorCode.EOPNOTSUPP.rawValue)
207+
expectEqual(EPFNOSUPPORT, POSIXErrorCode.EPFNOSUPPORT.rawValue)
208+
expectEqual(EAFNOSUPPORT, POSIXErrorCode.EAFNOSUPPORT.rawValue)
209+
expectEqual(EADDRINUSE, POSIXErrorCode.EADDRINUSE.rawValue)
210+
expectEqual(EADDRNOTAVAIL, POSIXErrorCode.EADDRNOTAVAIL.rawValue)
211+
expectEqual(ENETDOWN, POSIXErrorCode.ENETDOWN.rawValue)
212+
expectEqual(ENETUNREACH, POSIXErrorCode.ENETUNREACH.rawValue)
213+
expectEqual(ENETRESET, POSIXErrorCode.ENETRESET.rawValue)
214+
expectEqual(ECONNABORTED, POSIXErrorCode.ECONNABORTED.rawValue)
215+
expectEqual(ECONNRESET, POSIXErrorCode.ECONNRESET.rawValue)
216+
expectEqual(ENOBUFS, POSIXErrorCode.ENOBUFS.rawValue)
217+
expectEqual(EISCONN, POSIXErrorCode.EISCONN.rawValue)
218+
expectEqual(ENOTCONN, POSIXErrorCode.ENOTCONN.rawValue)
219+
expectEqual(ESHUTDOWN, POSIXErrorCode.ESHUTDOWN.rawValue)
220+
expectEqual(ETOOMANYREFS, POSIXErrorCode.ETOOMANYREFS.rawValue)
221+
expectEqual(ETIMEDOUT, POSIXErrorCode.ETIMEDOUT.rawValue)
222+
expectEqual(ECONNREFUSED, POSIXErrorCode.ECONNREFUSED.rawValue)
223+
expectEqual(ELOOP, POSIXErrorCode.ELOOP.rawValue)
224+
expectEqual(ENAMETOOLONG, POSIXErrorCode.ENAMETOOLONG.rawValue)
225+
expectEqual(EHOSTDOWN, POSIXErrorCode.EHOSTDOWN.rawValue)
226+
expectEqual(EHOSTUNREACH, POSIXErrorCode.EHOSTUNREACH.rawValue)
227+
expectEqual(ENOTEMPTY, POSIXErrorCode.ENOTEMPTY.rawValue)
228+
expectEqual(EPROCLIM, POSIXErrorCode.EPROCLIM.rawValue)
229+
expectEqual(EUSERS, POSIXErrorCode.EUSERS.rawValue)
230+
expectEqual(EDQUOT, POSIXErrorCode.EDQUOT.rawValue)
231+
expectEqual(ESTALE, POSIXErrorCode.ESTALE.rawValue)
232+
expectEqual(EREMOTE, POSIXErrorCode.EREMOTE.rawValue)
233+
expectEqual(EBADRPC, POSIXErrorCode.EBADRPC.rawValue)
234+
expectEqual(ERPCMISMATCH, POSIXErrorCode.ERPCMISMATCH.rawValue)
235+
expectEqual(EPROGUNAVAIL, POSIXErrorCode.EPROGUNAVAIL.rawValue)
236+
expectEqual(EPROGMISMATCH, POSIXErrorCode.EPROGMISMATCH.rawValue)
237+
expectEqual(EPROCUNAVAIL, POSIXErrorCode.EPROCUNAVAIL.rawValue)
238+
expectEqual(ENOLCK, POSIXErrorCode.ENOLCK.rawValue)
239+
expectEqual(ENOSYS, POSIXErrorCode.ENOSYS.rawValue)
240+
expectEqual(EFTYPE, POSIXErrorCode.EFTYPE.rawValue)
241+
expectEqual(EAUTH, POSIXErrorCode.EAUTH.rawValue)
242+
expectEqual(ENEEDAUTH, POSIXErrorCode.ENEEDAUTH.rawValue)
243+
expectEqual(EIPSEC, POSIXErrorCode.EIPSEC.rawValue)
244+
expectEqual(ENOATTR, POSIXErrorCode.ENOATTR.rawValue)
245+
expectEqual(EILSEQ, POSIXErrorCode.EILSEQ.rawValue)
246+
expectEqual(ENOMEDIUM, POSIXErrorCode.ENOMEDIUM.rawValue)
247+
expectEqual(EMEDIUMTYPE, POSIXErrorCode.EMEDIUMTYPE.rawValue)
248+
expectEqual(EOVERFLOW, POSIXErrorCode.EOVERFLOW.rawValue)
249+
expectEqual(ECANCELED, POSIXErrorCode.ECANCELED.rawValue)
250+
expectEqual(EIDRM, POSIXErrorCode.EIDRM.rawValue)
251+
expectEqual(ENOMSG, POSIXErrorCode.ENOMSG.rawValue)
252+
expectEqual(ENOTSUP, POSIXErrorCode.ENOTSUP.rawValue)
253+
expectEqual(EBADMSG, POSIXErrorCode.EBADMSG.rawValue)
254+
expectEqual(ENOTRECOVERABLE, POSIXErrorCode.ENOTRECOVERABLE.rawValue)
255+
expectEqual(EOWNERDEAD, POSIXErrorCode.EOWNERDEAD.rawValue)
256+
expectEqual(EPROTO, POSIXErrorCode.EPROTO.rawValue)
257+
258+
expectEqual(EWOULDBLOCK, POSIXErrorCode.EAGAIN.rawValue)
259+
}
159260

160261
#endif
161262

0 commit comments

Comments
 (0)