Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
411 changes: 411 additions & 0 deletions Proposals/0010-win32-namespace-and-error.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Sources/System/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ target_sources(SystemPackage PRIVATE
Internals/RawBuffer.swift
Internals/Syscalls.swift
Internals/WindowsSyscallAdapters.swift)
target_sources(SystemPackage PRIVATE
Win32/Win32.swift
Win32/Win32Error.swift)
target_link_libraries(SystemPackage PUBLIC
CSystem)

Expand Down
15 changes: 14 additions & 1 deletion Sources/System/ErrnoWindows.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift System open source project

Copyright (c) 2024 Apple Inc. and the Swift System project authors
Copyright (c) 2024 - 2026 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand All @@ -17,4 +17,17 @@ extension Errno {
}
}

@available(System 199, *)
extension Errno {
/// Creates the closest POSIX ``Errno`` for a Windows system error.
///
/// This mapping is lossy. It approximates the C runtime's `_dosmaperr`,
/// folding Windows' several thousand system error codes onto a small set
/// of ``Errno`` values. Unrecognized codes become ``Errno/invalidArgument``.
/// Prefer handling ``Win32Error`` directly.
public init(approximating error: Win32Error) {
self.init(windowsError: error.rawValue)
}
}

#endif
28 changes: 28 additions & 0 deletions Sources/System/Win32/Win32.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift System open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift System project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

#if os(Windows)
/// A namespace for Win32 APIs on Windows.
///
/// The types and functions nested here wrap the Win32 base API, the
/// documented, ABI-stable system interface for desktop Windows.
@frozen
@available(System 199, *)
public enum Win32 {}
#elseif SYSTEM_PACKAGE
// Package builds on other platforms get unavailable stubs for `Win32` and
// `Win32Error`. Non-package builds omit them to avoid exporting ABI symbols.
@available(*, unavailable, message: "Win32 APIs are only available on Windows.")
public enum Win32 {}

@available(*, unavailable, message: "Win32 APIs are only available on Windows.")
public struct Win32Error: Error {}
#endif
Loading
Loading