Skip to content

Commit 2c8ff0a

Browse files
committed
Address ambiguous usage of open(2) constants.
1 parent aaafc72 commit 2c8ff0a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Sources/Foundation/NSData.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,10 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
464464
// and the compiler will throw an error.
465465
#if os(Windows)
466466
let createMode = Int(ucrt.S_IREAD) | Int(ucrt.S_IWRITE)
467-
#else
467+
#elseif canImport(Darwin)
468468
let createMode = Int(S_IRUSR) | Int(S_IWUSR) | Int(S_IRGRP) | Int(S_IWGRP) | Int(S_IROTH) | Int(S_IWOTH)
469+
#else
470+
let createMode = Int(Glibc.S_IRUSR) | Int(Glibc.S_IWUSR) | Int(Glibc.S_IRGRP) | Int(Glibc.S_IWGRP) | Int(Glibc.S_IROTH) | Int(Glibc.S_IWOTH)
469471
#endif
470472
guard let fh = FileHandle(path: path, flags: flags, createMode: createMode) else {
471473
throw _NSErrorWithErrno(errno, reading: false, path: path)

Tests/Foundation/Tests/TestNSData.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,12 @@ class TestNSData: LoopbackServerTest {
581581
try data.write(to: url)
582582
let fileManager = FileManager.default
583583
let permission = try fileManager._permissionsOfItem(atPath: url.path)
584-
XCTAssertEqual(0o666, permission)
584+
#if canImport(Darwin)
585+
let expected = Int(S_IRUSR) | Int(S_IWUSR) | Int(S_IRGRP) | Int(S_IWGRP) | Int(S_IROTH) | Int(S_IWOTH)
586+
#else
587+
let expected = Int(Glibc.S_IRUSR) | Int(Glibc.S_IWUSR) | Int(Glibc.S_IRGRP) | Int(Glibc.S_IWGRP) | Int(Glibc.S_IROTH) | Int(Glibc.S_IWOTH)
588+
#endif
589+
XCTAssertEqual(permission, expected)
585590
try! fileManager.removeItem(atPath: url.path)
586591
} catch {
587592
XCTFail()
@@ -599,7 +604,12 @@ class TestNSData: LoopbackServerTest {
599604
try data.write(to: url, options: .atomic)
600605
let fileManager = FileManager.default
601606
let permission = try fileManager._permissionsOfItem(atPath: url.path)
602-
XCTAssertEqual(0o666, permission)
607+
#if canImport(Darwin)
608+
let expected = Int(S_IRUSR) | Int(S_IWUSR) | Int(S_IRGRP) | Int(S_IWGRP) | Int(S_IROTH) | Int(S_IWOTH)
609+
#else
610+
let expected = Int(Glibc.S_IRUSR) | Int(Glibc.S_IWUSR) | Int(Glibc.S_IRGRP) | Int(Glibc.S_IWGRP) | Int(Glibc.S_IROTH) | Int(Glibc.S_IWOTH)
611+
#endif
612+
XCTAssertEqual(permission, expected)
603613
try! fileManager.removeItem(atPath: url.path)
604614
} catch {
605615
XCTFail()

0 commit comments

Comments
 (0)