mirror of
https://github.com/apple/swift-system
synced 2026-11-27 05:04:27 +00:00
Changes after comments from Saleem.
Use idiomatic Swift notation, not `Optional<Bool>`. Prefer Win32 APIs to UCRT APIs. rdar://125087707
This commit is contained in:
1 parent
85de4e51e2
commit
4cafcc96f6
3 files changed
+17
-7
No files matched your search
@@ -29,8 +29,7 @@ internal func getTemporaryDirectory() throws -> FilePath {
|
||||
capacity: Int(MAX_PATH) + 1) {
|
||||
buffer in
|
||||
|
||||
let count = GetTempPath2W(DWORD(buffer.count), buffer.baseAddress)
|
||||
if count == 0 {
|
||||
guard GetTempPath2W(DWORD(buffer.count), buffer.baseAddress) != 0 else {
|
||||
throw Errno(windowsError: GetLastError())
|
||||
}
|
||||
|
||||
@@ -116,7 +115,7 @@ internal func getTemporaryDirectory() throws -> FilePath {
|
||||
while true {
|
||||
let path: FilePath? = withUnsafeTemporaryAllocation(
|
||||
of: CInterop.PlatformChar.self,
|
||||
capacity: 1024) { buffer in
|
||||
capacity: capacity) { buffer in
|
||||
let len = system_confstr(SYSTEM_CS_DARWIN_USER_TEMP_DIR,
|
||||
buffer.baseAddress!,
|
||||
buffer.count)
|
||||
|
||||
@@ -110,7 +110,7 @@ private var contextualMockingEnabled: Bool {
|
||||
extension MockingDriver {
|
||||
internal static var enabled: Bool { mockingEnabled }
|
||||
|
||||
internal static var forceWindowsPaths: Optional<Bool> {
|
||||
internal static var forceWindowsPaths: Bool? {
|
||||
currentMockingDriver?.forceWindowsSyntaxForPaths
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ internal var mockingEnabled: Bool {
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
internal var forceWindowsPaths: Optional<Bool> {
|
||||
internal var forceWindowsPaths: Bool? {
|
||||
#if !ENABLE_MOCKING
|
||||
return false
|
||||
#else
|
||||
|
||||
@@ -160,14 +160,25 @@ internal func mkdir(
|
||||
_ path: UnsafePointer<CInterop.PlatformChar>,
|
||||
_ mode: CInterop.Mode
|
||||
) -> CInt {
|
||||
return _wmkdir(path)
|
||||
// TODO: Read/write permissions (these need mapping to a SECURITY_DESCRIPTOR).
|
||||
if !CreateDirectoryW(path, nil) {
|
||||
ucrt._set_errno(mapWindowsErrorToErrno(GetLastError()))
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
internal func rmdir(
|
||||
_ path: UnsafePointer<CInterop.PlatformChar>
|
||||
) -> CInt {
|
||||
return _wrmdir(path)
|
||||
if !RemoveDirectoryW(path) {
|
||||
ucrt._set_errno(mapWindowsErrorToErrno(GetLastError()))
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
|
||||
Reference in new issue
Block a user