@@ -141,7 +141,7 @@ struct FileHandle: ~Copyable, Sendable {
141
141
/// descriptor, `nil` is passed to `body`.
142
142
borrowing func withUnsafePOSIXFileDescriptor< R> ( _ body: ( CInt ? ) throws -> R ) rethrows -> R {
143
143
try withUnsafeCFILEHandle { handle in
144
- #if SWT_TARGET_OS_APPLE || os(Linux)
144
+ #if SWT_TARGET_OS_APPLE || os(Linux) || os(WASI)
145
145
let fd = fileno ( handle)
146
146
#elseif os(Windows)
147
147
let fd = _fileno ( handle)
@@ -210,6 +210,8 @@ struct FileHandle: ~Copyable, Sendable {
210
210
defer {
211
211
_unlock_file ( handle)
212
212
}
213
+ #elseif os(WASI)
214
+ // No file locking on WASI yet.
213
215
#else
214
216
#warning("Platform-specific implementation missing: cannot lock a file handle")
215
217
#endif
@@ -233,7 +235,7 @@ extension FileHandle {
233
235
// If possible, reserve enough space in the resulting buffer to contain
234
236
// the contents of the file being read.
235
237
var size : Int ?
236
- #if SWT_TARGET_OS_APPLE || os(Linux)
238
+ #if SWT_TARGET_OS_APPLE || os(Linux) || os(WASI)
237
239
withUnsafePOSIXFileDescriptor { fd in
238
240
var s = stat ( )
239
241
if let fd, 0 == fstat ( fd, & s) {
@@ -371,7 +373,7 @@ extension FileHandle {
371
373
extension FileHandle {
372
374
/// Is this file handle a TTY or PTY?
373
375
var isTTY : Bool {
374
- #if SWT_TARGET_OS_APPLE || os(Linux)
376
+ #if SWT_TARGET_OS_APPLE || os(Linux) || os(WASI)
375
377
// If stderr is a TTY and TERM is set, that's good enough for us.
376
378
withUnsafePOSIXFileDescriptor { fd in
377
379
if let fd, 0 != isatty ( fd) , let term = Environment . variable ( named: " TERM " ) , !term. isEmpty {
@@ -397,7 +399,7 @@ extension FileHandle {
397
399
398
400
/// Is this file handle a pipe or FIFO?
399
401
var isPipe : Bool {
400
- #if SWT_TARGET_OS_APPLE || os(Linux)
402
+ #if SWT_TARGET_OS_APPLE || os(Linux) || os(WASI)
401
403
withUnsafePOSIXFileDescriptor { fd in
402
404
guard let fd else {
403
405
return false
0 commit comments