Skip to content

Commit 0627d28

Browse files
authored
Merge pull request #6 from compnerd/windows
Initial port to Windows
2 parents 0b0d9d5 + 4ffcc62 commit 0627d28

File tree

8 files changed

+396
-2
lines changed

8 files changed

+396
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
This source file is part of the Swift System open source project
3+
4+
Copyright (c) 2020 Apple Inc. and the Swift System project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
*/
9+
10+
#if defined(_WIN32)
11+
12+
#define NOMINMAX
13+
#define WIN32_LEAN_AND_MEAN
14+
#define VC_EXTRA_LEAN
15+
#include <Windows.h>
16+
17+
#endif

Sources/CSystem/shims.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111

1212
#include <CSystemLinux.h>
1313

14-
#endif
14+
#endif
15+
16+
#if defined(_WIN32)
17+
#include <CSystemWindows.h>
18+
#endif

Sources/System/Errno.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
229229
@available(*, unavailable, renamed: "badAddress")
230230
public static var EFAULT: Errno { badAddress }
231231

232+
#if !os(Windows)
232233
/// Not a block device.
233234
///
234235
/// You attempted a block device operation on a nonblock device or file.
@@ -240,6 +241,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
240241
@_alwaysEmitIntoClient
241242
@available(*, unavailable, renamed: "notBlockDevice")
242243
public static var ENOTBLK: Errno { notBlockDevice }
244+
#endif
243245

244246
/// Resource busy.
245247
///
@@ -360,6 +362,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
360362
@available(*, unavailable, renamed: "tooManyOpenFiles")
361363
public static var EMFILE: Errno { tooManyOpenFiles }
362364

365+
#if !os(Windows)
363366
/// Inappropriate control function.
364367
///
365368
/// You attempted a control function
@@ -388,6 +391,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
388391
@_alwaysEmitIntoClient
389392
@available(*, unavailable, renamed: "textFileBusy")
390393
public static var ETXTBSY: Errno { textFileBusy }
394+
#endif
391395

392396
/// The file is too large.
393397
///
@@ -630,6 +634,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
630634
@available(*, unavailable, renamed: "socketTypeNotSupported")
631635
public static var ESOCKTNOSUPPORT: Errno { socketTypeNotSupported }
632636

637+
#if !os(Windows)
633638
/// Not supported.
634639
///
635640
/// The attempted operation isn't supported
@@ -642,6 +647,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
642647
@_alwaysEmitIntoClient
643648
@available(*, unavailable, renamed: "notSupported")
644649
public static var ENOTSUP: Errno { notSupported }
650+
#endif
645651

646652
/// Protocol family not supported.
647653
///
@@ -1123,6 +1129,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
11231129
public static var EDEVERR: Errno { deviceError }
11241130
#endif
11251131

1132+
#if !os(Windows)
11261133
/// Value too large to be stored in data type.
11271134
///
11281135
/// A numerical result of the function
@@ -1135,6 +1142,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
11351142
@_alwaysEmitIntoClient
11361143
@available(*, unavailable, renamed: "overflow")
11371144
public static var EOVERFLOW: Errno { overflow }
1145+
#endif
11381146

11391147
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11401148
/// Bad executable or shared library.
@@ -1199,6 +1207,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
11991207
@available(*, unavailable, renamed: "canceled")
12001208
public static var ECANCELED: Errno { canceled }
12011209

1210+
#if !os(Windows)
12021211
/// Identifier removed.
12031212
///
12041213
/// An IPC identifier was removed while the current process was waiting on it.
@@ -1223,6 +1232,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
12231232
@_alwaysEmitIntoClient
12241233
@available(*, unavailable, renamed: "noMessage")
12251234
public static var ENOMSG: Errno { noMessage }
1235+
#endif
12261236

12271237
/// Illegal byte sequence.
12281238
///
@@ -1252,6 +1262,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
12521262
public static var ENOATTR: Errno { attributeNotFound }
12531263
#endif
12541264

1265+
#if !os(Windows)
12551266
/// Bad message.
12561267
///
12571268
/// The message to be received is inappropriate
@@ -1350,6 +1361,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
13501361
@_alwaysEmitIntoClient
13511362
@available(*, unavailable, renamed: "timeout")
13521363
public static var ETIME: Errno { timeout }
1364+
#endif
13531365

13541366
/// Operation not supported on socket.
13551367
///
@@ -1411,6 +1423,7 @@ extension Errno {
14111423
public static var ENOPOLICY: Errno { noSuchPolicy }
14121424
#endif
14131425

1426+
#if !os(Windows)
14141427
/// State not recoverable.
14151428
///
14161429
/// The corresponding C error is `ENOTRECOVERABLE`.
@@ -1430,6 +1443,7 @@ extension Errno {
14301443
@_alwaysEmitIntoClient
14311444
@available(*, unavailable, renamed: "previousOwnerDied")
14321445
public static var EOWNERDEAD: Errno { previousOwnerDied }
1446+
#endif
14331447

14341448
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
14351449
/// Interface output queue is full.

Sources/System/FileDescriptor.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ extension FileDescriptor {
8383
@_alwaysEmitIntoClient
8484
private init(_ raw: CInt) { self.init(rawValue: raw) }
8585

86+
#if !os(Windows)
8687
/// Indicates that opening the file doesn't
8788
/// wait for the file or device to become available.
8889
///
@@ -103,6 +104,7 @@ extension FileDescriptor {
103104
@_alwaysEmitIntoClient
104105
@available(*, unavailable, renamed: "nonBlocking")
105106
public static var O_NONBLOCK: OpenOptions { nonBlocking }
107+
#endif
106108

107109
/// Indicates that each write operation appends to the file.
108110
///
@@ -201,6 +203,7 @@ extension FileDescriptor {
201203
public static var O_EXLOCK: OpenOptions { exclusiveLock }
202204
#endif
203205

206+
#if !os(Windows)
204207
/// Indicates that opening the file doesn't follow symlinks.
205208
///
206209
/// If you specify this option
@@ -216,6 +219,7 @@ extension FileDescriptor {
216219
@_alwaysEmitIntoClient
217220
@available(*, unavailable, renamed: "noFollow")
218221
public static var O_NOFOLLOW: OpenOptions { noFollow }
222+
#endif
219223

220224
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
221225
/// Indicates that opening the file
@@ -252,6 +256,7 @@ extension FileDescriptor {
252256
public static var O_EVTONLY: OpenOptions { eventOnly }
253257
#endif
254258

259+
#if !os(Windows)
255260
/// Indicates that executing a program closes the file.
256261
///
257262
/// Normally, file descriptors remain open
@@ -271,6 +276,7 @@ extension FileDescriptor {
271276
@_alwaysEmitIntoClient
272277
@available(*, unavailable, renamed: "closeOnExec")
273278
public static var O_CLOEXEC: OpenOptions { closeOnExec }
279+
#endif
274280
}
275281

276282
/// Options for specifying what a file descriptor's offset is relative to.
@@ -413,6 +419,13 @@ extension FileDescriptor.OpenOptions
413419
(.eventOnly, ".eventOnly"),
414420
(.closeOnExec, ".closeOnExec")
415421
]
422+
#elseif os(Windows)
423+
let descriptions: [(Element, StaticString)] = [
424+
(.append, ".append"),
425+
(.create, ".create"),
426+
(.truncate, ".truncate"),
427+
(.exclusiveCreate, ".exclusiveCreate"),
428+
]
416429
#else
417430
let descriptions: [(Element, StaticString)] = [
418431
(.nonBlocking, ".nonBlocking"),

Sources/System/Platform.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
1616
// @available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
1717
public typealias CModeT = UInt16
18+
#elseif os(Windows)
19+
public typealias CModeT = Int32
1820
#else
1921
public typealias CModeT = UInt32
2022
#endif

0 commit comments

Comments
 (0)