Skip to content

Commit ac9640b

Browse files
committed
[stdlib] Changes to support Foundation on OpenBSD.
* Not implementing POSIXError for a given platform is not a blocking problem to getting a successful build of Swift. However, it is part of the validation tests (albeit locked behind REQUIRES) and is referenced when building Foundation. Implement by forklifting from `sys/errno.h`. * Some Foundation class implementations require some missing includes in the platform modulemap. Add these.
1 parent 191dc14 commit ac9640b

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
@@ -682,4 +682,202 @@ public enum POSIXErrorCode : Int32 {
682682
case STRUNCATE = 80
683683
}
684684

685+
#elseif os(OpenBSD)
686+
687+
/// Enumeration describing POSIX error codes.
688+
public enum POSIXErrorCode : Int32 {
689+
/// Operation not permitted
690+
case EPERM = 1
691+
/// No such file or directory
692+
case ENOENT = 2
693+
/// No such process
694+
case ESRCH = 3
695+
/// Interrupted system call
696+
case EINTR = 4
697+
/// Input/output error
698+
case EIO = 5
699+
/// Device not configured
700+
case ENXIO = 6
701+
/// Argument list too long
702+
case E2BIG = 7
703+
/// Exec format error
704+
case ENOEXEC = 8
705+
/// Bad file descriptor
706+
case EBADF = 9
707+
/// No child processes
708+
case ECHILD = 10
709+
/// Resource deadlock avoided
710+
case EDEADLK = 11
711+
/// Cannot allocate memory
712+
case ENOMEM = 12
713+
/// Permission denied
714+
case EACCES = 13
715+
/// Bad address
716+
case EFAULT = 14
717+
/// Block device required
718+
case ENOTBLK = 15
719+
/// Device busy
720+
case EBUSY = 16
721+
/// File exists
722+
case EEXIST = 17
723+
/// Cross-device link
724+
case EXDEV = 18
725+
/// Operation not supported by device
726+
case ENODEV = 19
727+
/// Not a directory
728+
case ENOTDIR = 20
729+
/// Is a directory
730+
case EISDIR = 21
731+
/// Invalid argument
732+
case EINVAL = 22
733+
/// Too many open files in system
734+
case ENFILE = 23
735+
/// Too many open files
736+
case EMFILE = 24
737+
/// Inappropriate ioctl for device
738+
case ENOTTY = 25
739+
/// Text file busy
740+
case ETXTBSY = 26
741+
/// File too large
742+
case EFBIG = 27
743+
/// No space left on device
744+
case ENOSPC = 28
745+
/// Illegal seek
746+
case ESPIPE = 29
747+
/// Read-only file system
748+
case EROFS = 30
749+
/// Too many links
750+
case EMLINK = 31
751+
/// Broken pipe
752+
case EPIPE = 32
753+
/// Numerical argument out of domain
754+
case EDOM = 33
755+
/// Result too large
756+
case ERANGE = 34
757+
/// Resource temporarily unavailable
758+
case EAGAIN = 35
759+
/// Operation would block
760+
public static var EWOULDBLOCK: POSIXErrorCode { return .EAGAIN }
761+
/// Operation now in progress
762+
case EINPROGRESS = 36
763+
/// Operation already in progress
764+
case EALREADY = 37
765+
/// Socket operation on non-socket
766+
case ENOTSOCK = 38
767+
/// Destination address required
768+
case EDESTADDRREQ = 39
769+
/// Message too long
770+
case EMSGSIZE = 40
771+
/// Protocol wrong type for socket
772+
case EPROTOTYPE = 41
773+
/// Protocol not available
774+
case ENOPROTOOPT = 42
775+
/// Protocol not supported
776+
case EPROTONOSUPPORT = 43
777+
/// Socket type not supported
778+
case ESOCKTNOSUPPORT = 44
779+
/// Operation not supported
780+
case EOPNOTSUPP = 45
781+
/// Protocol family not supported
782+
case EPFNOSUPPORT = 46
783+
/// Address family not supported by protocol family
784+
case EAFNOSUPPORT = 47
785+
/// Address already in use
786+
case EADDRINUSE = 48
787+
/// Can't assign requested address
788+
case EADDRNOTAVAIL = 49
789+
/// Network is down
790+
case ENETDOWN = 50
791+
/// Network is unreachable
792+
case ENETUNREACH = 51
793+
/// Network dropped connection on reset
794+
case ENETRESET = 52
795+
/// Software caused connection abort
796+
case ECONNABORTED = 53
797+
/// Connection reset by peer
798+
case ECONNRESET = 54
799+
/// No buffer space available
800+
case ENOBUFS = 55
801+
/// Socket is already connected
802+
case EISCONN = 56
803+
/// Socket is not connected
804+
case ENOTCONN = 57
805+
/// Can't send after socket shutdown
806+
case ESHUTDOWN = 58
807+
/// Too many references: can't splice
808+
case ETOOMANYREFS = 59
809+
/// Operation timed out
810+
case ETIMEDOUT = 60
811+
/// Connection refused
812+
case ECONNREFUSED = 61
813+
/// Too many levels of symbolic links
814+
case ELOOP = 62
815+
/// File name too long
816+
case ENAMETOOLONG = 63
817+
/// Host is down
818+
case EHOSTDOWN = 64
819+
/// No route to host
820+
case EHOSTUNREACH = 65
821+
/// Directory not empty
822+
case ENOTEMPTY = 66
823+
/// Too many processes
824+
case EPROCLIM = 67
825+
/// Too many users
826+
case EUSERS = 68
827+
/// Disk quota exceeded
828+
case EDQUOT = 69
829+
/// Stale NFS file handle
830+
case ESTALE = 70
831+
/// Too many levels of remote in path
832+
case EREMOTE = 71
833+
/// RPC struct is bad
834+
case EBADRPC = 72
835+
/// RPC version wrong
836+
case ERPCMISMATCH = 73
837+
/// RPC program not available
838+
case EPROGUNAVAIL = 74
839+
/// Program version wrong
840+
case EPROGMISMATCH = 75
841+
/// Bad procedure for program
842+
case EPROCUNAVAIL = 76
843+
/// No locks available
844+
case ENOLCK = 77
845+
/// Function not implemented
846+
case ENOSYS = 78
847+
/// Inappropriate file type or format
848+
case EFTYPE = 79
849+
/// Authentication error
850+
case EAUTH = 80
851+
/// Need authenticator
852+
case ENEEDAUTH = 81
853+
/// IPsec processing failure
854+
case EIPSEC = 82
855+
/// Attribute not found
856+
case ENOATTR = 83
857+
/// Illegal byte sequence
858+
case EILSEQ = 84
859+
/// No medium found
860+
case ENOMEDIUM = 85
861+
/// Wrong medium type
862+
case EMEDIUMTYPE = 86
863+
/// Value too large to be stored in data type
864+
case EOVERFLOW = 87
865+
/// Operation canceled
866+
case ECANCELED = 88
867+
/// Identifier removed
868+
case EIDRM = 89
869+
/// No message of desired type
870+
case ENOMSG = 90
871+
/// Not supported
872+
case ENOTSUP = 91
873+
/// Bad message
874+
case EBADMSG = 92
875+
/// State not recoverable
876+
case ENOTRECOVERABLE = 93
877+
/// Previous owner died
878+
case EOWNERDEAD = 94
879+
/// Protocol error
880+
case EPROTO = 95
881+
}
882+
685883
#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)