-
Notifications
You must be signed in to change notification settings - Fork 90
Import ucrt on Windows if available
#294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Joannis
wants to merge
12
commits into
apple:main
Choose a base branch
from
Joannis:jo/windows-ucrt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lukasa
reviewed
Nov 4, 2025
…between Windows and POSIX
Lukasa
approved these changes
Nov 5, 2025
Contributor
Lukasa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thanks @Joannis.
Contributor
|
Looks like there are format tweaks that need to happen. |
Contributor
Author
|
@Lukasa I tried |
Contributor
|
It would probably be enough to apply this diff: diff --git a/Package.swift b/Package.swift
index 0707fe6..7d6d0dd 100644
--- a/Package.swift
+++ b/Package.swift
@@ -111,7 +111,7 @@ var targets: [PackageDescription.Target] = [
name: "CNIOExtrasZlib",
dependencies: [],
cSettings: [
- .define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
+ .define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows]))
],
linkerSettings: [
.linkedLibrary("z", .when(platforms: [.linux, .macOS, .iOS, .tvOS, .watchOS, .visionOS])),
diff --git a/Sources/HTTPServerWithQuiescingDemo/main.swift b/Sources/HTTPServerWithQuiescingDemo/main.swift
index 41c1458..a84ba37 100644
--- a/Sources/HTTPServerWithQuiescingDemo/main.swift
+++ b/Sources/HTTPServerWithQuiescingDemo/main.swift
@@ -136,4 +136,4 @@ private func runServer() throws {
try runServer()
#else
print("This demo is not supported on Windows.")
-#endif
\ No newline at end of file
+#endif
diff --git a/Sources/NIOExtras/WritePCAPHandler.swift b/Sources/NIOExtras/WritePCAPHandler.swift
index 2e02cac..23c9978 100644
--- a/Sources/NIOExtras/WritePCAPHandler.swift
+++ b/Sources/NIOExtras/WritePCAPHandler.swift
@@ -26,21 +26,21 @@ import Android
import ucrt
import WinSDK
-fileprivate func gettimeofday(_ tp: inout timeval, _ tzp: Never?) {
+private func gettimeofday(_ tp: inout timeval, _ tzp: Never?) {
var file_time = FILETIME()
var system_time = SYSTEMTIME()
var time: UInt64 = 0
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
- // until 00:00:00 January 1, 1970
- let epoch: UInt64 = 116444736000000000
+ // until 00:00:00 January 1, 1970
+ let epoch: UInt64 = 116_444_736_000_000_000
- GetSystemTime(&system_time);
- SystemTimeToFileTime(&system_time, &file_time);
- time = UInt64(file_time.dwLowDateTime)
+ GetSystemTime(&system_time)
+ SystemTimeToFileTime(&system_time, &file_time)
+ time = UInt64(file_time.dwLowDateTime)
time += UInt64(file_time.dwHighDateTime) << 32
- tp.tv_sec = Int32((time - epoch) / 10000000)
+ tp.tv_sec = Int32((time - epoch) / 10_000_000)
tp.tv_usec = Int32(system_time.wMilliseconds * 1000)
}
#else
@@ -752,7 +752,14 @@ extension NIOWritePCAPHandler {
) throws -> SynchronizedFileSink {
#if os(Windows)
let fd = try path.withCString(encodedAs: UTF16.self) { pathPtr -> CInt in
- let fd = _wsopen_s(nil, pathPtr, _O_WRONLY | (fileWritingMode == FileWritingMode.createNewPCAPFile ? (_O_TRUNC | _O_CREAT) : _O_APPEND), _SH_DENYNO, _S_IREAD | _S_IWRITE)
+ let fd = _wsopen_s(
+ nil,
+ pathPtr,
+ _O_WRONLY
+ | (fileWritingMode == FileWritingMode.createNewPCAPFile ? (_O_TRUNC | _O_CREAT) : _O_APPEND),
+ _SH_DENYNO,
+ _S_IREAD | _S_IWRITE
+ )
guard fd >= 0 else {
throw SynchronizedFileSink.Error(errorCode: Error.ErrorCode.cannotOpenFileError.rawValue)
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This should enable NIOExtras to work on Windows, except for modules that depend on NIOSSL.