Skip to content

Commit ca0a622

Browse files
authored
Merge pull request swiftlang#21293 from compnerd/msvcrt-fileio
Platform: make MSVCRT more Unix-libc like
2 parents 917b500 + 04a5d84 commit ca0a622

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

stdlib/public/Platform/Platform.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import SwiftShims
1414
import SwiftOverlayShims
1515

16+
#if os(Windows)
17+
import ucrt
18+
#endif
19+
1620
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1721
//===----------------------------------------------------------------------===//
1822
// MacTypes.h
@@ -132,6 +136,14 @@ public func snprintf(ptr: UnsafeMutablePointer<Int8>, _ len: Int, _ format: Unsa
132136
return vsnprintf(ptr, len, format, va_args)
133137
}
134138
}
139+
#elseif os(Windows)
140+
public var stdin: UnsafeMutablePointer<FILE> { return __acrt_iob_func(0) }
141+
public var stdout: UnsafeMutablePointer<FILE> { return __acrt_iob_func(1) }
142+
public var stderr: UnsafeMutablePointer<FILE> { return __acrt_iob_func(2) }
143+
144+
public var STDIN_FILENO: Int32 { return _fileno(stdin) }
145+
public var STDOUT_FILENO: Int32 { return _fileno(stdout) }
146+
public var STDERR_FILENO: Int32 { return _fileno(stderr) }
135147
#endif
136148

137149

stdlib/public/Platform/ucrt.modulemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module ucrt [system] {
111111

112112
module corecrt {
113113
header "corecrt.h"
114+
header "corecrt_stdio_config.h"
114115
export *
115116

116117
module io {
@@ -122,6 +123,11 @@ module ucrt [system] {
122123
header "corecrt_math.h"
123124
export *
124125
}
126+
127+
module stdio {
128+
header "corecrt_wstdio.h"
129+
export *
130+
}
125131
}
126132
}
127133

0 commit comments

Comments
 (0)