Skip to content

Commit 2febbb4

Browse files
committed
stdlib: implement POSIXErrorCode for FreeBSD
It shares many of the same values as OpenBSD (which both inherited from 4.4BSD), and we wouldn't expect those to diverge due to the respective platforms' bincompat goals.
1 parent 7727ce7 commit 2febbb4

File tree

2 files changed

+141
-2
lines changed

2 files changed

+141
-2
lines changed

stdlib/public/Platform/POSIXError.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ public enum POSIXErrorCode : Int32 {
850850
case STRUNCATE = 80
851851
}
852852

853-
#elseif os(OpenBSD)
853+
#elseif os(OpenBSD) || os(FreeBSD)
854854

855855
/// Enumeration describing POSIX error codes.
856856
public enum POSIXErrorCode : Int32 {
@@ -1018,6 +1018,8 @@ public enum POSIXErrorCode : Int32 {
10181018
case EAUTH = 80
10191019
/// Need authenticator
10201020
case ENEEDAUTH = 81
1021+
1022+
#if os(OpenBSD)
10211023
/// IPsec processing failure
10221024
case EIPSEC = 82
10231025
/// Attribute not found
@@ -1046,6 +1048,40 @@ public enum POSIXErrorCode : Int32 {
10461048
case EOWNERDEAD = 94
10471049
/// Protocol error
10481050
case EPROTO = 95
1051+
#elseif os(FreeBSD)
1052+
/// Identifier removed
1053+
case EIDRM = 82
1054+
/// No message of desired type
1055+
case ENOMSG = 83
1056+
/// Value too large to be stored in data type
1057+
case EOVERFLOW = 84
1058+
/// Operation canceled
1059+
case ECANCELED = 85
1060+
/// Illegal byte sequence
1061+
case EILSEQ = 86
1062+
/// Attribute not found
1063+
case ENOATTR = 87
1064+
/// Programming error
1065+
case EDOOFUS = 88
1066+
/// Bad message
1067+
case EBADMSG = 89
1068+
/// Multihop attempted
1069+
case EMULTIHOP = 90
1070+
/// Link has been severed
1071+
case ENOLINK = 91
1072+
/// Protocol error
1073+
case EPROTO = 92
1074+
/// Capabilities insufficient
1075+
case ENOTCAPABLE = 93
1076+
/// Not permitted in capability mode
1077+
case ECAPMODE = 94
1078+
/// State not recoverable
1079+
case ENOTRECOVERABLE = 95
1080+
/// Previous owner died
1081+
case EOWNERDEAD = 96
1082+
/// Integrity check failed
1083+
case EINTEGRITY = 97
1084+
#endif
10491085
}
10501086

10511087
#endif

validation-test/stdlib/POSIXErrorCode.swift

Lines changed: 104 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 || OS=openbsd
3+
// REQUIRES: VENDOR=apple || OS=linux-androideabi || OS=linux-android || OS=linux-gnu || OS=openbsd || OS=freebsd
44
// UNSUPPORTED: freestanding
55

66
import Swift
@@ -156,6 +156,7 @@ POSIXErrorCodeTestSuite.test("Linux POSIX error codes constants") {
156156
expectEqual(EOWNERDEAD, POSIXErrorCode.EOWNERDEAD.rawValue)
157157
expectEqual(ENOTRECOVERABLE, POSIXErrorCode.ENOTRECOVERABLE.rawValue)
158158
}
159+
159160
#elseif os(OpenBSD)
160161

161162
POSIXErrorCodeTestSuite.test("OpenBSD POSIX error codes constants") {
@@ -258,6 +259,108 @@ POSIXErrorCodeTestSuite.test("OpenBSD POSIX error codes constants") {
258259
expectEqual(EWOULDBLOCK, POSIXErrorCode.EAGAIN.rawValue)
259260
}
260261

262+
#elseif os(FreeBSD)
263+
264+
POSIXErrorCodeTestSuite.test("FreeBSD POSIX error codes constants") {
265+
expectEqual(EPERM, POSIXErrorCode.EPERM.rawValue)
266+
expectEqual(ENOENT, POSIXErrorCode.ENOENT.rawValue)
267+
expectEqual(ESRCH, POSIXErrorCode.ESRCH.rawValue)
268+
expectEqual(EINTR, POSIXErrorCode.EINTR.rawValue)
269+
expectEqual(EIO, POSIXErrorCode.EIO.rawValue)
270+
expectEqual(ENXIO, POSIXErrorCode.ENXIO.rawValue)
271+
expectEqual(E2BIG, POSIXErrorCode.E2BIG.rawValue)
272+
expectEqual(ENOEXEC, POSIXErrorCode.ENOEXEC.rawValue)
273+
expectEqual(EBADF, POSIXErrorCode.EBADF.rawValue)
274+
expectEqual(ECHILD, POSIXErrorCode.ECHILD.rawValue)
275+
expectEqual(EDEADLK, POSIXErrorCode.EDEADLK.rawValue)
276+
expectEqual(ENOMEM, POSIXErrorCode.ENOMEM.rawValue)
277+
expectEqual(EACCES, POSIXErrorCode.EACCES.rawValue)
278+
expectEqual(EFAULT, POSIXErrorCode.EFAULT.rawValue)
279+
expectEqual(ENOTBLK, POSIXErrorCode.ENOTBLK.rawValue)
280+
expectEqual(EBUSY, POSIXErrorCode.EBUSY.rawValue)
281+
expectEqual(EEXIST, POSIXErrorCode.EEXIST.rawValue)
282+
expectEqual(EXDEV, POSIXErrorCode.EXDEV.rawValue)
283+
expectEqual(ENODEV, POSIXErrorCode.ENODEV.rawValue)
284+
expectEqual(ENOTDIR, POSIXErrorCode.ENOTDIR.rawValue)
285+
expectEqual(EISDIR, POSIXErrorCode.EISDIR.rawValue)
286+
expectEqual(EINVAL, POSIXErrorCode.EINVAL.rawValue)
287+
expectEqual(ENFILE, POSIXErrorCode.ENFILE.rawValue)
288+
expectEqual(EMFILE, POSIXErrorCode.EMFILE.rawValue)
289+
expectEqual(ENOTTY, POSIXErrorCode.ENOTTY.rawValue)
290+
expectEqual(ETXTBSY, POSIXErrorCode.ETXTBSY.rawValue)
291+
expectEqual(EFBIG, POSIXErrorCode.EFBIG.rawValue)
292+
expectEqual(ENOSPC, POSIXErrorCode.ENOSPC.rawValue)
293+
expectEqual(ESPIPE, POSIXErrorCode.ESPIPE.rawValue)
294+
expectEqual(EROFS, POSIXErrorCode.EROFS.rawValue)
295+
expectEqual(EMLINK, POSIXErrorCode.EMLINK.rawValue)
296+
expectEqual(EPIPE, POSIXErrorCode.EPIPE.rawValue)
297+
expectEqual(EDOM, POSIXErrorCode.EDOM.rawValue)
298+
expectEqual(ERANGE, POSIXErrorCode.ERANGE.rawValue)
299+
expectEqual(EAGAIN, POSIXErrorCode.EAGAIN.rawValue)
300+
expectEqual(EINPROGRESS, POSIXErrorCode.EINPROGRESS.rawValue)
301+
expectEqual(EALREADY, POSIXErrorCode.EALREADY.rawValue)
302+
expectEqual(ENOTSOCK, POSIXErrorCode.ENOTSOCK.rawValue)
303+
expectEqual(EDESTADDRREQ, POSIXErrorCode.EDESTADDRREQ.rawValue)
304+
expectEqual(EMSGSIZE, POSIXErrorCode.EMSGSIZE.rawValue)
305+
expectEqual(EPROTOTYPE, POSIXErrorCode.EPROTOTYPE.rawValue)
306+
expectEqual(ENOPROTOOPT, POSIXErrorCode.ENOPROTOOPT.rawValue)
307+
expectEqual(EPROTONOSUPPORT, POSIXErrorCode.EPROTONOSUPPORT.rawValue)
308+
expectEqual(ESOCKTNOSUPPORT, POSIXErrorCode.ESOCKTNOSUPPORT.rawValue)
309+
expectEqual(EOPNOTSUPP, POSIXErrorCode.EOPNOTSUPP.rawValue)
310+
expectEqual(EPFNOSUPPORT, POSIXErrorCode.EPFNOSUPPORT.rawValue)
311+
expectEqual(EAFNOSUPPORT, POSIXErrorCode.EAFNOSUPPORT.rawValue)
312+
expectEqual(EADDRINUSE, POSIXErrorCode.EADDRINUSE.rawValue)
313+
expectEqual(EADDRNOTAVAIL, POSIXErrorCode.EADDRNOTAVAIL.rawValue)
314+
expectEqual(ENETDOWN, POSIXErrorCode.ENETDOWN.rawValue)
315+
expectEqual(ENETUNREACH, POSIXErrorCode.ENETUNREACH.rawValue)
316+
expectEqual(ENETRESET, POSIXErrorCode.ENETRESET.rawValue)
317+
expectEqual(ECONNABORTED, POSIXErrorCode.ECONNABORTED.rawValue)
318+
expectEqual(ECONNRESET, POSIXErrorCode.ECONNRESET.rawValue)
319+
expectEqual(ENOBUFS, POSIXErrorCode.ENOBUFS.rawValue)
320+
expectEqual(EISCONN, POSIXErrorCode.EISCONN.rawValue)
321+
expectEqual(ENOTCONN, POSIXErrorCode.ENOTCONN.rawValue)
322+
expectEqual(ESHUTDOWN, POSIXErrorCode.ESHUTDOWN.rawValue)
323+
expectEqual(ETOOMANYREFS, POSIXErrorCode.ETOOMANYREFS.rawValue)
324+
expectEqual(ETIMEDOUT, POSIXErrorCode.ETIMEDOUT.rawValue)
325+
expectEqual(ECONNREFUSED, POSIXErrorCode.ECONNREFUSED.rawValue)
326+
expectEqual(ELOOP, POSIXErrorCode.ELOOP.rawValue)
327+
expectEqual(ENAMETOOLONG, POSIXErrorCode.ENAMETOOLONG.rawValue)
328+
expectEqual(EHOSTDOWN, POSIXErrorCode.EHOSTDOWN.rawValue)
329+
expectEqual(EHOSTUNREACH, POSIXErrorCode.EHOSTUNREACH.rawValue)
330+
expectEqual(ENOTEMPTY, POSIXErrorCode.ENOTEMPTY.rawValue)
331+
expectEqual(EPROCLIM, POSIXErrorCode.EPROCLIM.rawValue)
332+
expectEqual(EUSERS, POSIXErrorCode.EUSERS.rawValue)
333+
expectEqual(EDQUOT, POSIXErrorCode.EDQUOT.rawValue)
334+
expectEqual(ESTALE, POSIXErrorCode.ESTALE.rawValue)
335+
expectEqual(EREMOTE, POSIXErrorCode.EREMOTE.rawValue)
336+
expectEqual(EBADRPC, POSIXErrorCode.EBADRPC.rawValue)
337+
expectEqual(ERPCMISMATCH, POSIXErrorCode.ERPCMISMATCH.rawValue)
338+
expectEqual(EPROGUNAVAIL, POSIXErrorCode.EPROGUNAVAIL.rawValue)
339+
expectEqual(EPROGMISMATCH, POSIXErrorCode.EPROGMISMATCH.rawValue)
340+
expectEqual(EPROCUNAVAIL, POSIXErrorCode.EPROCUNAVAIL.rawValue)
341+
expectEqual(ENOLCK, POSIXErrorCode.ENOLCK.rawValue)
342+
expectEqual(ENOSYS, POSIXErrorCode.ENOSYS.rawValue)
343+
expectEqual(EFTYPE, POSIXErrorCode.EFTYPE.rawValue)
344+
expectEqual(EAUTH, POSIXErrorCode.EAUTH.rawValue)
345+
expectEqual(ENEEDAUTH, POSIXErrorCode.ENEEDAUTH.rawValue)
346+
expectEqual(EIDRM, POSIXErrorCode.EIDRM.rawValue)
347+
expectEqual(ENOMSG, POSIXErrorCode.ENOMSG.rawValue)
348+
expectEqual(EOVERFLOW, POSIXErrorCode.EOVERFLOW.rawValue)
349+
expectEqual(ECANCELED, POSIXErrorCode.ECANCELED.rawValue)
350+
expectEqual(EILSEQ, POSIXErrorCode.EILSEQ.rawValue)
351+
expectEqual(ENOATTR, POSIXErrorCode.ENOATTR.rawValue)
352+
expectEqual(EDOOFUS, POSIXErrorCode.EDOOFUS.rawValue)
353+
expectEqual(EBADMSG, POSIXErrorCode.EBADMSG.rawValue)
354+
expectEqual(EMULTIHOP, POSIXErrorCode.EMULTIHOP.rawValue)
355+
expectEqual(ENOLINK, POSIXErrorCode.ENOLINK.rawValue)
356+
expectEqual(EPROTO, POSIXErrorCode.EPROTO.rawValue)
357+
expectEqual(ENOTCAPABLE, POSIXErrorCode.ENOTCAPABLE.rawValue)
358+
expectEqual(ECAPMODE, POSIXErrorCode.ECAPMODE.rawValue)
359+
expectEqual(ENOTRECOVERABLE, POSIXErrorCode.ENOTRECOVERABLE.rawValue)
360+
expectEqual(EOWNERDEAD, POSIXErrorCode.EOWNERDEAD.rawValue)
361+
expectEqual(EINTEGRITY, POSIXErrorCode.EINTEGRITY.rawValue)
362+
}
363+
261364
#endif
262365

263366
runAllTests()

0 commit comments

Comments
 (0)