@@ -98,18 +98,29 @@ public var errno : Int32 {
98
98
get {
99
99
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4)
100
100
return __error ( ) . pointee
101
- // FIXME: os(Windows) should be replaced, such as triple(Cygwin)
102
- #elseif os(Android) || os(Windows)
101
+ #elseif os(Android)
103
102
return __errno ( ) . pointee
103
+ #elseif os(Windows)
104
+ #if CYGWIN
105
+ return __errno ( ) . pointee
106
+ #else
107
+ return _errno ( ) . pointee
108
+ #endif
104
109
#else
105
110
return __errno_location ( ) . pointee
106
111
#endif
107
112
}
108
113
set ( val) {
109
114
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS) || os(FreeBSD) || os(PS4)
110
115
return __error ( ) . pointee = val
111
- #elseif os(Android) || os(Windows)
116
+ #elseif os(Android)
117
+ return __errno ( ) . pointee = val
118
+ #elseif os(Windows)
119
+ #if CYGWIN
112
120
return __errno ( ) . pointee = val
121
+ #else
122
+ return _errno ( ) . pointee = val
123
+ #endif
113
124
#else
114
125
return __errno_location ( ) . pointee = val
115
126
#endif
@@ -165,20 +176,31 @@ public func snprintf(ptr: UnsafeMutablePointer<Int8>, _ len: Int, _ format: Unsa
165
176
// fcntl.h
166
177
//===----------------------------------------------------------------------===//
167
178
179
+ #if !os(Windows) || CYGWIN
168
180
@_silgen_name ( " _swift_Platform_open " )
169
181
func _swift_Platform_open(
170
182
_ path: UnsafePointer < CChar > ,
171
183
_ oflag: Int32 ,
172
184
_ mode: mode_t
173
185
) -> Int32
186
+ #else
187
+ @_silgen_name ( " _swift_Platform_open " )
188
+ func _swift_Platform_open(
189
+ _ path: UnsafePointer < CChar > ,
190
+ _ oflag: Int32 ,
191
+ _ mode: Int32
192
+ ) -> Int32
193
+ #endif
174
194
195
+ #if !os(Windows) || CYGWIN
175
196
@_silgen_name ( " _swift_Platform_openat " )
176
197
func _swift_Platform_openat(
177
198
_ fd: Int32 ,
178
199
_ path: UnsafePointer < CChar > ,
179
200
_ oflag: Int32 ,
180
201
_ mode: mode_t
181
202
) -> Int32
203
+ #endif
182
204
183
205
public func open(
184
206
_ path: UnsafePointer < CChar > ,
@@ -187,6 +209,7 @@ public func open(
187
209
return _swift_Platform_open ( path, oflag, 0 )
188
210
}
189
211
212
+ #if !os(Windows) || CYGWIN
190
213
public func open(
191
214
_ path: UnsafePointer < CChar > ,
192
215
_ oflag: Int32 ,
@@ -211,7 +234,17 @@ public func openat(
211
234
) -> Int32 {
212
235
return _swift_Platform_openat ( fd, path, oflag, mode)
213
236
}
237
+ #else
238
+ public func open(
239
+ _ path: UnsafePointer < CChar > ,
240
+ _ oflag: Int32 ,
241
+ _ mode: Int32
242
+ ) -> Int32 {
243
+ return _swift_Platform_open ( path, oflag, mode)
244
+ }
245
+ #endif
214
246
247
+ #if !os(Windows) || CYGWIN
215
248
@_silgen_name ( " _swift_Platform_fcntl " )
216
249
internal func _swift_Platform_fcntl(
217
250
_ fd: Int32 ,
@@ -248,7 +281,9 @@ public func fcntl(
248
281
) -> Int32 {
249
282
return _swift_Platform_fcntlPtr ( fd, cmd, ptr)
250
283
}
284
+ #endif
251
285
286
+ #if !os(Windows) || CYGWIN
252
287
public var S_IFMT : mode_t { return mode_t ( 0o170000 ) }
253
288
public var S_IFIFO : mode_t { return mode_t ( 0o010000 ) }
254
289
public var S_IFCHR : mode_t { return mode_t ( 0o020000 ) }
@@ -286,11 +321,24 @@ public var S_IREAD: mode_t { return S_IRUSR }
286
321
public var S_IWRITE : mode_t { return S_IWUSR }
287
322
public var S_IEXEC : mode_t { return S_IXUSR }
288
323
#endif
324
+ #else
325
+ public var S_IFMT : Int32 { return Int32 ( 0xf000 ) }
326
+
327
+ public var S_IFREG : Int32 { return Int32 ( 0x8000 ) }
328
+ public var S_IFDIR : Int32 { return Int32 ( 0x4000 ) }
329
+ public var S_IFCHR : Int32 { return Int32 ( 0x2000 ) }
330
+ public var S_IFIFO : Int32 { return Int32 ( 0x1000 ) }
331
+
332
+ public var S_IREAD : Int32 { return Int32 ( 0x0100 ) }
333
+ public var S_IWRITE : Int32 { return Int32 ( 0x0080 ) }
334
+ public var S_IEXEC : Int32 { return Int32 ( 0x0040 ) }
335
+ #endif
289
336
290
337
//===----------------------------------------------------------------------===//
291
338
// ioctl.h
292
339
//===----------------------------------------------------------------------===//
293
340
341
+ #if !os(Windows) || CYGWIN
294
342
@_silgen_name ( " _swift_Platform_ioctl " )
295
343
internal func _swift_Platform_ioctl(
296
344
_ fd: CInt ,
@@ -327,8 +375,8 @@ public func ioctl(
327
375
) -> CInt {
328
376
return _swift_Platform_ioctl ( fd, request, 0 )
329
377
}
330
-
331
-
378
+ #endif
379
+
332
380
//===----------------------------------------------------------------------===//
333
381
// unistd.h
334
382
//===----------------------------------------------------------------------===//
@@ -354,14 +402,22 @@ public var SIG_DFL: sig_t? { return nil }
354
402
public var SIG_IGN : sig_t { return unsafeBitCast ( 1 , to: sig_t. self) }
355
403
public var SIG_ERR : sig_t { return unsafeBitCast ( - 1 , to: sig_t. self) }
356
404
public var SIG_HOLD : sig_t { return unsafeBitCast ( 5 , to: sig_t. self) }
357
- #elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows)
358
- #if os(Windows)
359
- // In Cygwin, the below SIG_* have the same value with Linux.
360
- // Verified with libstdc++6 v5.3.0 in Cygwin v2.4.1 64bit.
361
- public typealias sighandler_t = _sig_func_ptr
362
- #else
405
+ #elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
406
+ public typealias sighandler_t = __sighandler_t
407
+
408
+ public var SIG_DFL : sighandler_t ? { return nil }
409
+ public var SIG_IGN : sighandler_t {
410
+ return unsafeBitCast ( 1 , to: sighandler_t. self)
411
+ }
412
+ public var SIG_ERR : sighandler_t {
413
+ return unsafeBitCast ( - 1 , to: sighandler_t. self)
414
+ }
415
+ public var SIG_HOLD : sighandler_t {
416
+ return unsafeBitCast ( 2 , to: sighandler_t. self)
417
+ }
418
+ #elseif os(Windows)
419
+ #if CYGWIN
363
420
public typealias sighandler_t = __sighandler_t
364
- #endif
365
421
366
422
public var SIG_DFL : sighandler_t ? { return nil }
367
423
public var SIG_IGN : sighandler_t {
@@ -374,21 +430,38 @@ public var SIG_HOLD: sighandler_t {
374
430
return unsafeBitCast ( 2 , to: sighandler_t. self)
375
431
}
376
432
#else
433
+ public var SIG_DFL : _crt_signal_t ? { return nil }
434
+ public var SIG_IGN : _crt_signal_t {
435
+ return unsafeBitCast ( 1 , to: _crt_signal_t. self)
436
+ }
437
+ public var SIG_ERR : _crt_signal_t {
438
+ return unsafeBitCast ( - 1 , to: _crt_signal_t. self)
439
+ }
440
+ #endif
441
+ #else
377
442
internal var _ignore = _UnsupportedPlatformError ( )
378
443
#endif
379
444
380
445
//===----------------------------------------------------------------------===//
381
446
// semaphore.h
382
447
//===----------------------------------------------------------------------===//
383
448
449
+ #if !os(Windows) || CYGWIN
384
450
/// The value returned by `sem_open()` in the case of failure.
385
451
public var SEM_FAILED : UnsafeMutablePointer < sem_t > ? {
386
452
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
387
453
// The value is ABI. Value verified to be correct for OS X, iOS, watchOS, tvOS.
388
454
return UnsafeMutablePointer < sem_t > ( bitPattern: - 1 )
389
- #elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Windows)
455
+ #elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
390
456
// The value is ABI. Value verified to be correct on Glibc.
391
457
return UnsafeMutablePointer < sem_t > ( bitPattern: 0 )
458
+ #elseif os(Windows)
459
+ #if CYGWIN
460
+ // The value is ABI. Value verified to be correct on Glibc.
461
+ return UnsafeMutablePointer < sem_t > ( bitPattern: 0 )
462
+ #else
463
+ _UnsupportedPlatformError ( )
464
+ #endif
392
465
#else
393
466
_UnsupportedPlatformError ( )
394
467
#endif
@@ -423,6 +496,7 @@ public func sem_open(
423
496
) -> UnsafeMutablePointer < sem_t > ? {
424
497
return _swift_Platform_sem_open4 ( name, oflag, mode, value)
425
498
}
499
+ #endif
426
500
427
501
//===----------------------------------------------------------------------===//
428
502
// Misc.
0 commit comments