Skip to content

Commit 578586a

Browse files
committed
Un-deprecate withCString
Un-deprecate withCString, but make sure it's not available on Windows (because the types will not match). withPlatformString is still the preferred expression of this and favors more portable code.
1 parent 8e3c239 commit 578586a

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Sources/System/FilePath/FilePathString.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extension FilePath {
3636
public func withPlatformString<Result>(
3737
_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result
3838
) rethrows -> Result {
39+
// For backwards deployment, call withCString if available.
3940
#if !os(Windows)
4041
return try withCString(body)
4142
#else
@@ -399,25 +400,21 @@ extension String {
399400
public init?(validatingUTF8 path: FilePath) { self.init(validating: path) }
400401
}
401402

403+
#if !os(Windows)
402404
// @available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
403405
extension FilePath {
404-
@available(*, deprecated, renamed: "init(platformString:)")
406+
/// For backwards compatibility only. This initializer is equivalent to
407+
/// the preferred `FilePath(platformString:)`.
405408
public init(cString: UnsafePointer<CChar>) {
406-
#if os(Windows)
407-
fatalError("FilePath.init(cString:) unsupported on Windows ")
408-
#else
409409
self.init(platformString: cString)
410-
#endif
411410
}
412411

413-
@available(*, deprecated, renamed: "withPlatformString(_:)")
412+
/// For backwards compatibility only. This function is equivalent to
413+
/// the preferred `withPlatformString`.
414414
public func withCString<Result>(
415415
_ body: (UnsafePointer<CChar>) throws -> Result
416416
) rethrows -> Result {
417-
#if os(Windows)
418-
fatalError("FilePath.withCString() unsupported on Windows ")
419-
#else
420417
return try _withPlatformString(body)
421-
#endif
422418
}
423419
}
420+
#endif

0 commit comments

Comments
 (0)