Skip to content

Commit ef1c56e

Browse files
committed
Add necessary missing TARGET_OS_BSD directives.
A number of Foundation tests are failing on OpenBSD due to these missing directives, or are required for other reasons. There is still more complex work to get full support for Foundation on this platform but this will be handled in other commits.
1 parent 931dd5f commit ef1c56e

File tree

22 files changed

+80
-80
lines changed

22 files changed

+80
-80
lines changed

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ enum {
10341034
};
10351035
#endif // __has_include(<dispatch/private.h>)
10361036

1037-
#if TARGET_OS_LINUX || TARGET_OS_WIN32
1037+
#if TARGET_OS_LINUX || TARGET_OS_WIN32 || TARGET_OS_BSD
10381038
#define QOS_CLASS_USER_INITIATED DISPATCH_QUEUE_PRIORITY_HIGH
10391039
#define QOS_CLASS_DEFAULT DISPATCH_QUEUE_PRIORITY_DEFAULT
10401040
#define QOS_CLASS_UTILITY DISPATCH_QUEUE_PRIORITY_LOW

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ int _CFOpenFile(const char *path, int opts) {
16491649
}
16501650

16511651
CF_CROSS_PLATFORM_EXPORT void *_CFReallocf(void *ptr, size_t size) {
1652-
#if TARGET_OS_WIN32 || TARGET_OS_LINUX
1652+
#if TARGET_OS_WIN32 || TARGET_OS_LINUX || defined(__OpenBSD__)
16531653
void *mem = realloc(ptr, size);
16541654
if (mem == NULL && ptr != NULL && size != 0) {
16551655
free(ptr);

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ extern CFTypeID CFTreeGetTypeID(void);
972972
extern CFTypeID CFPlugInInstanceGetTypeID(void);
973973
extern CFTypeID CFStringTokenizerGetTypeID(void);
974974
extern CFTypeID CFStorageGetTypeID(void);
975-
#if TARGET_OS_LINUX || (TARGET_OS_OSX && !DEPLOYMENT_RUNTIME_OBJC)
975+
#if TARGET_OS_LINUX || TARGET_OS_BSD || (TARGET_OS_OSX && !DEPLOYMENT_RUNTIME_OBJC)
976976
CF_PRIVATE void __CFTSDInitialize(void);
977977
#endif
978978
#if TARGET_OS_WIN32
@@ -1105,7 +1105,7 @@ Boolean __CFInitialized = 0;
11051105
// move the next 2 lines down into the #if below, and make it static, after Foundation gets off this symbol on other platforms.
11061106
CF_EXPORT _CFThreadRef _CFMainPThread;
11071107
_CFThreadRef _CFMainPThread = kNilPthreadT;
1108-
#if TARGET_OS_WIN32 || TARGET_OS_LINUX
1108+
#if TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
11091109

11101110
CF_EXPORT _CFThreadRef _CF_pthread_main_thread_np(void);
11111111
_CFThreadRef _CF_pthread_main_thread_np(void) {
@@ -1144,7 +1144,7 @@ void __CFInitialize(void) {
11441144
#if TARGET_OS_WIN32
11451145
// Must not call any CF functions
11461146
__CFTSDWindowsInitialize();
1147-
#elif TARGET_OS_LINUX || (TARGET_OS_MAC && !DEPLOYMENT_RUNTIME_OBJC)
1147+
#elif TARGET_OS_LINUX || TARGET_OS_BSD || (TARGET_OS_MAC && !DEPLOYMENT_RUNTIME_OBJC)
11481148
__CFTSDInitialize();
11491149
#endif
11501150
__CFProphylacticAutofsAccess = true;

CoreFoundation/Base.subproj/CFUUID.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ CFUUIDRef CFUUIDCreate(CFAllocatorRef alloc) {
152152
long rStatus = UuidCreate(&u);
153153
if (RPC_S_OK != rStatus && RPC_S_UUID_LOCAL_ONLY != rStatus) retval = 1;
154154
memmove(&bytes, &u, sizeof(bytes));
155-
#elif TARGET_OS_MAC || TARGET_OS_LINUX
155+
#elif TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
156156
static int8_t useV1UUIDs = -1;
157157
uuid_t uuid;
158158
if (useV1UUIDs == -1) {

CoreFoundation/Base.subproj/CoreFoundation_Prefix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ CF_INLINE uint64_t mach_absolute_time() {
222222
ULONGLONG ullTime;
223223
QueryUnbiasedInterruptTimePrecise(&ullTime);
224224
return ullTime;
225-
#else
225+
#elif TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_MAC
226226
struct timespec ts;
227227
clock_gettime(CLOCK_MONOTONIC, &ts);
228228
return (uint64_t)ts.tv_nsec + (uint64_t)ts.tv_sec * 1000000000UL;

CoreFoundation/Locale.subproj/CFDateFormatter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@ static UDate __CFDateFormatterCorrectTimeToARangeAroundCurrentDate(UCalendar *ca
15061506
return __CFDateFormatterCorrectTimeWithTarget(calendar, at, currEraOrCentury+offset, isEra, status);
15071507
}
15081508

1509-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
1509+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
15101510
static int32_t __CFDateFormatterGetMaxYearGivenJapaneseEra(UCalendar *calendar, int32_t era, UErrorCode *status) {
15111511
int32_t years = 0;
15121512
__cficu_ucal_clear(calendar);
@@ -1559,7 +1559,7 @@ static Boolean __CFDateFormatterHandleAmbiguousYear(CFDateFormatterRef formatter
15591559
}
15601560
}
15611561
} else if (calendar_id == kCFCalendarIdentifierJapanese) { // ??? need more work
1562-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
1562+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
15631563
__cficu_ucal_clear(cal);
15641564
__cficu_ucal_set(cal, UCAL_ERA, 1);
15651565
__cficu_udat_parseCalendar(df, cal, ustr, length, NULL, status);

CoreFoundation/Locale.subproj/CFLocale.c

Lines changed: 35 additions & 35 deletions
Large diffs are not rendered by default.

CoreFoundation/Locale.subproj/CFLocaleIdentifier.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#include <string.h>
5959
#include <stdlib.h>
6060
#include <stdio.h>
61-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
61+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
6262
#include <unicode/uloc.h>
6363
#else
6464
#define ULOC_KEYWORD_SEPARATOR '@'
@@ -1157,7 +1157,7 @@ enum {
11571157
};
11581158
*/
11591159

1160-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
1160+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
11611161

11621162
struct LocaleToLegacyCodes {
11631163
const char * locale; // reduced to language plus one other component (script, region, variant), separators normalized to'_'
@@ -1595,7 +1595,7 @@ static void _UpdateFullLocaleString(char inLocaleString[], int locStringMaxLen,
15951595
// If so, copy the keywords to varKeyValueString and delete the variant tag
15961596
// from the original string (but don't otherwise use the ICU canonicalization).
15971597
varKeyValueString[0] = 0;
1598-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
1598+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
15991599
if (variantTag) {
16001600
UErrorCode icuStatus;
16011601
int icuCanonStringLen;
@@ -1722,7 +1722,7 @@ static void _GetKeyValueString(char inLocaleString[], char keyValueString[]) {
17221722
}
17231723

17241724
static void _AppendKeyValueString(char inLocaleString[], int locStringMaxLen, char keyValueString[]) {
1725-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
1725+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
17261726
if (keyValueString[0] != 0) {
17271727
UErrorCode uerr = U_ZERO_ERROR;
17281728
UEnumeration * uenum = uloc_openKeywords(keyValueString, &uerr);
@@ -1954,12 +1954,12 @@ SPI: CFLocaleGetLanguageRegionEncodingForLocaleIdentifier gets the appropriate
19541954
preferred localization in the current context (this function returns NO for a NULL localeIdentifier); and in this function
19551955
langCode, regCode, and scriptCode are all SInt16* (not SInt32* like the equivalent parameters in CFBundleGetLocalizationInfoForLocalization).
19561956
*/
1957-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
1957+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
19581958
static int CompareLocaleToLegacyCodesEntries( const void *entry1, const void *entry2 );
19591959
#endif
19601960

19611961
Boolean CFLocaleGetLanguageRegionEncodingForLocaleIdentifier(CFStringRef localeIdentifier, LangCode *langCode, RegionCode *regCode, ScriptCode *scriptCode, CFStringEncoding *stringEncoding) {
1962-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
1962+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
19631963
Boolean returnValue = false;
19641964
CFStringRef canonicalIdentifier = CFLocaleCreateCanonicalLocaleIdentifierFromString(NULL, localeIdentifier);
19651965
if (canonicalIdentifier) {
@@ -2037,7 +2037,7 @@ Boolean CFLocaleGetLanguageRegionEncodingForLocaleIdentifier(CFStringRef localeI
20372037
#endif
20382038
}
20392039

2040-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
2040+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
20412041
static int CompareLocaleToLegacyCodesEntries( const void *entry1, const void *entry2 ) {
20422042
const char * localeString1 = ((const LocaleToLegacyCodes *)entry1)->locale;
20432043
const char * localeString2 = ((const LocaleToLegacyCodes *)entry2)->locale;
@@ -2047,7 +2047,7 @@ static int CompareLocaleToLegacyCodesEntries( const void *entry1, const void *en
20472047

20482048
CFDictionaryRef CFLocaleCreateComponentsFromLocaleIdentifier(CFAllocatorRef allocator, CFStringRef localeID) {
20492049
CFMutableDictionaryRef working = CFDictionaryCreateMutable(allocator, 10, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
2050-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
2050+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
20512051
char cLocaleID[ULOC_FULLNAME_CAPACITY+ULOC_KEYWORD_AND_VALUES_CAPACITY];
20522052
char buffer[ULOC_FULLNAME_CAPACITY+ULOC_KEYWORD_AND_VALUES_CAPACITY];
20532053

@@ -2177,7 +2177,7 @@ CFStringRef CFLocaleCreateLocaleIdentifierFromComponents(CFAllocatorRef allocato
21772177
free(variant);
21782178
free(buf1);
21792179

2180-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
2180+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
21812181
for (CFIndex idx = 0; idx < cnt; idx++) {
21822182
if (keys[idx]) {
21832183
char *key = __CStringFromString(keys[idx]);

CoreFoundation/Preferences.subproj/CFPreferences.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static CFStringRef _CFPreferencesStandardDomainCacheKey(CFStringRef domainName
420420
static CFURLRef _CFPreferencesURLForStandardDomainWithSafetyLevel(CFStringRef domainName, CFStringRef userName, CFStringRef hostName, unsigned long safeLevel) {
421421
CFURLRef theURL = NULL;
422422
CFAllocatorRef prefAlloc = __CFPreferencesAllocator();
423-
#if TARGET_OS_OSX || TARGET_OS_WIN32 || TARGET_OS_LINUX
423+
#if TARGET_OS_OSX || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
424424
CFURLRef prefDir = _preferencesCreateDirectoryForUserHostSafetyLevel(userName, hostName, safeLevel);
425425
CFStringRef appName;
426426
CFStringRef fileName;
@@ -454,7 +454,7 @@ static CFURLRef _CFPreferencesURLForStandardDomainWithSafetyLevel(CFStringRef do
454454
CFRelease(appName);
455455
}
456456
if (fileName) {
457-
#if TARGET_OS_MAC || TARGET_OS_LINUX
457+
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
458458
theURL = CFURLCreateWithFileSystemPathRelativeToBase(prefAlloc, fileName, kCFURLPOSIXPathStyle, false, prefDir);
459459
#elif TARGET_OS_WIN32
460460
theURL = CFURLCreateWithFileSystemPathRelativeToBase(prefAlloc, fileName, kCFURLWindowsPathStyle, false, prefDir);

CoreFoundation/String.subproj/CFString.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "CFRuntime_Internal.h"
2929
#include <assert.h>
3030
#include <unicode/uchar.h>
31-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
31+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
3232
#include "CFLocaleInternal.h"
3333
#include "CFStringLocalizedFormattingInternal.h"
3434
#endif
@@ -453,7 +453,7 @@ CF_INLINE CFStringEncoding __CFStringGetSystemEncoding(void) {
453453

454454
CFStringEncoding CFStringFileSystemEncoding(void) {
455455
if (__CFDefaultFileSystemEncoding == kCFStringEncodingInvalidId) {
456-
#if TARGET_OS_MAC || TARGET_OS_WIN32
456+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_BSD
457457
__CFDefaultFileSystemEncoding = kCFStringEncodingUTF8;
458458
#else
459459
__CFDefaultFileSystemEncoding = CFStringGetSystemEncoding();
@@ -6102,7 +6102,7 @@ enum {
61026102
CFFormatDummyPointerType = 42 /* special case for %n */
61036103
};
61046104

6105-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
6105+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
61066106
/* Only come in here if spec->type is CFFormatLongType or CFFormatDoubleType. Pass in 0 for width or precision if not specified. Returns false if couldn't do the format (with the assumption the caller falls back to unlocalized).
61076107
*/
61086108
static Boolean __CFStringFormatLocalizedNumber(CFMutableStringRef output, CFLocaleRef locale, const CFPrintValue *values, const CFFormatSpec *spec, SInt32 width, SInt32 precision, Boolean hasPrecision) {
@@ -7198,7 +7198,7 @@ static Boolean __CFStringAppendFormatCore(CFMutableStringRef outputString, CFStr
71987198
switch (specs[curSpec].type) {
71997199
case CFFormatLongType:
72007200
case CFFormatDoubleType:
7201-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
7201+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
72027202
if (localizedFormatting && (specs[curSpec].flags & kCFStringFormatLocalizable)) { // We have a locale, so we do localized formatting
72037203
if (__CFStringFormatLocalizedNumber(outputString, (CFLocaleRef)formatOptions, values, &specs[curSpec], width, precision, hasPrecision)) break;
72047204
}
@@ -7276,7 +7276,7 @@ static Boolean __CFStringAppendFormatCore(CFMutableStringRef outputString, CFStr
72767276
}
72777277
// See if we need to localize the decimal point
72787278
if (formatOptions) { // We have localization info
7279-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
7279+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_BSD
72807280
CFStringRef decimalSeparator = (CFGetTypeID(formatOptions) == CFLocaleGetTypeID()) ? (CFStringRef)CFLocaleGetValue((CFLocaleRef)formatOptions, kCFLocaleDecimalSeparatorKey) : (CFStringRef)CFDictionaryGetValue(formatOptions, CFSTR("NSDecimalSeparator"));
72817281
#else
72827282
CFStringRef decimalSeparator = CFSTR(".");

CoreFoundation/StringEncodings.subproj/CFStringEncodingDatabase.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ CF_PRIVATE CFStringEncoding __CFStringEncodingGetFromCanonicalName(const char *c
568568
}
569569
#undef LENGTH_LIMIT
570570

571-
#if TARGET_OS_OSX || TARGET_OS_LINUX || TARGET_OS_WIN32
571+
#if TARGET_OS_OSX || TARGET_OS_LINUX || TARGET_OS_WIN32 || TARGET_OS_BSD
572572
// This list indexes from DOS range
573573
static uint16_t const __CFISO8859SimilarScriptList[] = {
574574
kCFStringEncodingMacRoman,
@@ -777,7 +777,7 @@ static const char * const __CFOtherNameList[] = {
777777
"Western (NextStep)",
778778
"Western (EBCDIC Latin 1)",
779779
};
780-
#endif /* TARGET_OS_OSX || TARGET_OS_LINUX || TARGET_OS_WIN32 */
780+
#endif /* TARGET_OS_OSX || TARGET_OS_LINUX || TARGET_OS_WIN32 || TARGET_OS_BSD */
781781

782782
CF_PRIVATE CFStringEncoding __CFStringEncodingGetMostCompatibleMacScript(CFStringEncoding encoding) {
783783
#if TARGET_OS_OSX || TARGET_OS_LINUX
@@ -817,7 +817,7 @@ CF_PRIVATE const char *__CFStringEncodingGetName(CFStringEncoding encoding) {
817817
case kCFStringEncodingUTF7: return "Unicode (UTF-7)"; break;
818818
}
819819

820-
#if TARGET_OS_OSX || TARGET_OS_LINUX || TARGET_OS_WIN32
820+
#if TARGET_OS_OSX || TARGET_OS_LINUX || TARGET_OS_WIN32 || TARGET_OS_BSD
821821
if (0x0200 == (encoding & 0x0F00)) {
822822
encoding &= 0x00FF;
823823

@@ -827,7 +827,7 @@ CF_PRIVATE const char *__CFStringEncodingGetName(CFStringEncoding encoding) {
827827

828828
if (kCFNotFound != index) return __CFOtherNameList[index];
829829
}
830-
#endif /* TARGET_OS_OSX || TARGET_OS_LINUX || TARGET_OS_WIN32 */
830+
#endif /* TARGET_OS_OSX || TARGET_OS_LINUX || TARGET_OS_WIN32 || TARGET_OS_BSD */
831831

832832
return NULL;
833833
}

CoreFoundation/URL.subproj/CFURL.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,7 @@ static CFURLRef _CFURLCreateWithFileSystemRepresentation(CFAllocatorRef allocato
22782278
#endif
22792279
struct __CFURL *result = NULL;
22802280
if (bufLen > 0) {
2281-
#if TARGET_OS_MAC || TARGET_OS_LINUX
2281+
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
22822282
Boolean isAbsolute = bufLen && (*buffer == '/');
22832283
Boolean addedPercentEncoding;
22842284
Boolean releaseBaseURL = false;

Sources/Foundation/FileManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ open class FileManager : NSObject {
388388
}
389389
#if os(macOS) || os(iOS)
390390
let modeT = number.uint16Value
391-
#elseif os(Linux) || os(Android) || os(Windows)
391+
#elseif os(Linux) || os(Android) || os(Windows) || os(OpenBSD)
392392
let modeT = number.uint32Value
393393
#endif
394394
#if os(Windows)

Sources/Foundation/Host.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ open class Host: NSObject {
271271
}
272272
var hints = addrinfo()
273273
hints.ai_family = PF_UNSPEC
274-
#if os(macOS) || os(iOS) || os(Android)
274+
#if os(macOS) || os(iOS) || os(Android) || os(OpenBSD)
275275
hints.ai_socktype = SOCK_STREAM
276276
#else
277277
hints.ai_socktype = Int32(SOCK_STREAM.rawValue)

Sources/Foundation/NSLock.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public protocol NSLocking {
2626
private typealias _MutexPointer = UnsafeMutablePointer<SRWLOCK>
2727
private typealias _RecursiveMutexPointer = UnsafeMutablePointer<CRITICAL_SECTION>
2828
private typealias _ConditionVariablePointer = UnsafeMutablePointer<CONDITION_VARIABLE>
29-
#elseif CYGWIN
29+
#elseif CYGWIN || os(OpenBSD)
3030
private typealias _MutexPointer = UnsafeMutablePointer<pthread_mutex_t?>
3131
private typealias _RecursiveMutexPointer = UnsafeMutablePointer<pthread_mutex_t?>
3232
private typealias _ConditionVariablePointer = UnsafeMutablePointer<pthread_cond_t?>
@@ -242,7 +242,7 @@ open class NSRecursiveLock: NSObject, NSLocking {
242242
InitializeConditionVariable(timeoutCond)
243243
InitializeSRWLock(timeoutMutex)
244244
#else
245-
#if CYGWIN
245+
#if CYGWIN || os(OpenBSD)
246246
var attrib : pthread_mutexattr_t? = nil
247247
#else
248248
var attrib = pthread_mutexattr_t()

Sources/Foundation/NSPlatform.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#if os(macOS) || os(iOS)
1111
fileprivate let _NSPageSize = Int(vm_page_size)
12-
#elseif os(Linux) || os(Android)
12+
#elseif os(Linux) || os(Android) || os(OpenBSD)
1313
fileprivate let _NSPageSize = Int(getpagesize())
1414
#elseif os(Windows)
1515
import WinSDK

Sources/Foundation/NSSwiftRuntime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// This mimics the behavior of the swift sdk overlay on Darwin
1515
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
1616
@_exported import Darwin
17-
#elseif os(Linux) || os(Android) || CYGWIN
17+
#elseif os(Linux) || os(Android) || CYGWIN || os(OpenBSD)
1818
@_exported import Glibc
1919
#elseif os(Windows)
2020
@_exported import CRT

Sources/Foundation/Process.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ open class Process: NSObject {
781781
}
782782

783783
var taskSocketPair : [Int32] = [0, 0]
784-
#if os(macOS) || os(iOS) || os(Android)
784+
#if os(macOS) || os(iOS) || os(Android) || os(OpenBSD)
785785
socketpair(AF_UNIX, SOCK_STREAM, 0, &taskSocketPair)
786786
#else
787787
socketpair(AF_UNIX, Int32(SOCK_STREAM.rawValue), 0, &taskSocketPair)
@@ -944,7 +944,7 @@ open class Process: NSObject {
944944
try _throwIfPosixError(_CFPosixSpawnFileActionsAddClose(fileActions, fd))
945945
}
946946

947-
#if canImport(Darwin) || os(Android)
947+
#if canImport(Darwin) || os(Android) || os(OpenBSD)
948948
var spawnAttrs: posix_spawnattr_t? = nil
949949
#else
950950
var spawnAttrs: posix_spawnattr_t = posix_spawnattr_t()

Sources/Foundation/Thread.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ open class Thread : NSObject {
211211
get { _attrStorage.value }
212212
set { _attrStorage.value = newValue }
213213
}
214-
#elseif CYGWIN
214+
#elseif CYGWIN || os(OpenBSD)
215215
internal var _attr : pthread_attr_t? = nil
216216
#else
217217
internal var _attr = pthread_attr_t()
@@ -251,7 +251,7 @@ open class Thread : NSObject {
251251
_status = .finished
252252
return
253253
}
254-
#if CYGWIN
254+
#if CYGWIN || os(OpenBSD)
255255
if let attr = self._attr {
256256
_thread = self.withRetainedReference {
257257
return _CFThreadCreate(attr, NSThreadStart, $0)
@@ -359,7 +359,7 @@ open class Thread : NSObject {
359359
let maxSupportedStackDepth = 128;
360360
let addrs = UnsafeMutablePointer<UnsafeMutableRawPointer?>.allocate(capacity: maxSupportedStackDepth)
361361
defer { addrs.deallocate() }
362-
#if os(Android)
362+
#if os(Android) || os(OpenBSD)
363363
let count = 0
364364
#elseif os(Windows)
365365
let count = RtlCaptureStackBackTrace(0, DWORD(maxSupportedStackDepth),
@@ -380,7 +380,7 @@ open class Thread : NSObject {
380380
}
381381

382382
open class var callStackSymbols: [String] {
383-
#if os(Android)
383+
#if os(Android) || os(OpenBSD)
384384
return []
385385
#elseif os(Windows)
386386
let hProcess: HANDLE = GetCurrentProcess()

Sources/UUID/uuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static inline void nanotime(struct timespec *tv) {
6161
tv->tv_nsec = now - (tv->tv_sec * 1000000000);
6262
}
6363

64-
#elif TARGET_OS_LINUX
64+
#elif TARGET_OS_LINUX || TARGET_OS_BSD
6565
#include <time.h>
6666

6767
static inline void nanotime(struct timespec *tv) {

Tests/Foundation/Tests/TestSocketPort.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TestSocketPort : XCTestCase {
2727
func tcpOrUdpPort(of socketPort: SocketPort) -> Int? {
2828
let data = socketPort.address
2929

30-
#if canImport(Darwin) || os(FreeBSD)
30+
#if canImport(Darwin) || os(FreeBSD) || os(OpenBSD)
3131
let familyOffset = 1
3232
#else
3333
let familyOffset = 0

0 commit comments

Comments
 (0)