-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathStat.swift
More file actions
683 lines (624 loc) · 20.8 KB
/
Copy pathStat.swift
File metadata and controls
683 lines (624 loc) · 20.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift System open source project
//
// Copyright (c) 2025 - 2026 Apple Inc. and the Swift System project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
#if !os(Windows)
// Must import here to use C stat properties in @_alwaysEmitIntoClient APIs.
#if SYSTEM_PACKAGE_DARWIN
import Darwin
#elseif canImport(Glibc)
internal import CSystem
import Glibc
#elseif canImport(Musl)
internal import CSystem
import Musl
#elseif canImport(WASILibc)
import WASILibc
#elseif canImport(Android)
internal import CSystem
import Android
#else
#error("Unsupported Platform")
#endif
// MARK: - Stat
/// A Swift wrapper of the C `stat` struct.
///
/// - Note: Only available on Unix-like platforms.
@frozen
@available(System 1.7.0, *)
public struct Stat: RawRepresentable, Sendable {
/// The raw C `stat` struct.
@_alwaysEmitIntoClient
public var rawValue: CInterop.Stat
/// Creates a Swift `Stat` from the raw C struct.
@_alwaysEmitIntoClient
public init(rawValue: CInterop.Stat) { self.rawValue = rawValue }
// MARK: Stat.Flags
/// Flags representing those passed to `fstatat()`.
@frozen
public struct Flags: OptionSet, Sendable, Hashable, Codable {
/// The raw C flags.
@_alwaysEmitIntoClient
public let rawValue: CInt
/// Creates a strongly-typed `Stat.Flags` from raw C flags.
@_alwaysEmitIntoClient
public init(rawValue: CInt) { self.rawValue = rawValue }
/// If the path ends with a symbolic link, return information about the link itself.
///
/// The corresponding C constant is `AT_SYMLINK_NOFOLLOW`.
@_alwaysEmitIntoClient
public static var symlinkNoFollow: Flags { Flags(rawValue: _AT_SYMLINK_NOFOLLOW) }
#if SYSTEM_PACKAGE_DARWIN
/// If the path ends with a symbolic link, return information about the link itself.
/// If _any_ symbolic link is encountered during path resolution, return an error.
///
/// The corresponding C constant is `AT_SYMLINK_NOFOLLOW_ANY`.
/// - Note: Only available on Darwin.
@_alwaysEmitIntoClient
public static var symlinkNoFollowAny: Flags { Flags(rawValue: _AT_SYMLINK_NOFOLLOW_ANY) }
#endif
#if canImport(Darwin, _version: 346) || os(FreeBSD)
/// If the path does not reside in the hierarchy beneath the starting directory, return an error.
///
/// The corresponding C constant is `AT_RESOLVE_BENEATH`.
/// - Note: Only available on Darwin and FreeBSD.
@_alwaysEmitIntoClient
public static var resolveBeneath: Flags { Flags(rawValue: _AT_RESOLVE_BENEATH) }
#endif
}
// MARK: Initializers
/// Creates a `Stat` struct from a `FilePath`.
///
/// `followTargetSymlink` determines the behavior if `path` ends with a symbolic link.
/// By default, `followTargetSymlink` is `true` and this initializer behaves like `stat()`.
/// If `followTargetSymlink` is set to `false`, this initializer behaves like `lstat()` and
/// returns information about the symlink itself.
///
/// The corresponding C function is `stat()` or `lstat()` as described above.
@_alwaysEmitIntoClient
public init(
_ path: FilePath,
followTargetSymlink: Bool = true,
retryOnInterrupt: Bool = true
) throws(Errno) {
self.rawValue = try path.withPlatformString {
Self._stat(
$0,
followTargetSymlink: followTargetSymlink,
retryOnInterrupt: retryOnInterrupt
)
}.get()
}
/// Creates a `Stat` struct from an `UnsafePointer<CChar>` path.
///
/// `followTargetSymlink` determines the behavior if `path` ends with a symbolic link.
/// By default, `followTargetSymlink` is `true` and this initializer behaves like `stat()`.
/// If `followTargetSymlink` is set to `false`, this initializer behaves like `lstat()` and
/// returns information about the symlink itself.
///
/// The corresponding C function is `stat()` or `lstat()` as described above.
@_alwaysEmitIntoClient
public init(
_ path: UnsafePointer<CChar>,
followTargetSymlink: Bool = true,
retryOnInterrupt: Bool = true
) throws(Errno) {
self.rawValue = try Self._stat(
path,
followTargetSymlink: followTargetSymlink,
retryOnInterrupt: retryOnInterrupt
).get()
}
@usableFromInline
internal static func _stat(
_ ptr: UnsafePointer<CChar>,
followTargetSymlink: Bool,
retryOnInterrupt: Bool
) -> Result<CInterop.Stat, Errno> {
var result = CInterop.Stat()
return nothingOrErrno(retryOnInterrupt: retryOnInterrupt) {
if followTargetSymlink {
system_stat(ptr, &result)
} else {
system_lstat(ptr, &result)
}
}.map { result }
}
/// Creates a `Stat` struct from a `FileDescriptor`.
///
/// The corresponding C function is `fstat()`.
@_alwaysEmitIntoClient
public init(
_ fd: FileDescriptor,
retryOnInterrupt: Bool = true
) throws(Errno) {
self.rawValue = try Self._fstat(
fd,
retryOnInterrupt: retryOnInterrupt
).get()
}
@usableFromInline
internal static func _fstat(
_ fd: FileDescriptor,
retryOnInterrupt: Bool
) -> Result<CInterop.Stat, Errno> {
var result = CInterop.Stat()
return nothingOrErrno(retryOnInterrupt: retryOnInterrupt) {
system_fstat(fd.rawValue, &result)
}.map { result }
}
/// Creates a `Stat` struct from a `FilePath` and `Flags`.
///
/// If `path` is relative, it is resolved against the current working directory.
///
/// The corresponding C function is `fstatat()`.
@_alwaysEmitIntoClient
public init(
_ path: FilePath,
flags: Stat.Flags,
retryOnInterrupt: Bool = true
) throws(Errno) {
self.rawValue = try path.withPlatformString {
Self._fstatat(
$0,
relativeTo: _AT_FDCWD,
flags: flags,
retryOnInterrupt: retryOnInterrupt
)
}.get()
}
/// Creates a `Stat` struct from a `FilePath` and `Flags`,
/// including a `FileDescriptor` to resolve a relative path.
///
/// If `path` is absolute (starts with a forward slash), then `fd` is ignored.
/// If `path` is relative, it is resolved against the directory given by `fd`.
///
/// The corresponding C function is `fstatat()`.
@_alwaysEmitIntoClient
public init(
_ path: FilePath,
relativeTo fd: FileDescriptor,
flags: Stat.Flags,
retryOnInterrupt: Bool = true
) throws(Errno) {
self.rawValue = try path.withPlatformString {
Self._fstatat(
$0,
relativeTo: fd.rawValue,
flags: flags,
retryOnInterrupt: retryOnInterrupt
)
}.get()
}
/// Creates a `Stat` struct from an `UnsafePointer<CChar>` path and `Flags`.
///
/// If `path` is relative, it is resolved against the current working directory.
///
/// The corresponding C function is `fstatat()`.
@_alwaysEmitIntoClient
public init(
_ path: UnsafePointer<CChar>,
flags: Stat.Flags,
retryOnInterrupt: Bool = true
) throws(Errno) {
self.rawValue = try Self._fstatat(
path,
relativeTo: _AT_FDCWD,
flags: flags,
retryOnInterrupt: retryOnInterrupt
).get()
}
/// Creates a `Stat` struct from an `UnsafePointer<CChar>` path and `Flags`,
/// including a `FileDescriptor` to resolve a relative path.
///
/// If `path` is absolute (starts with a forward slash), then `fd` is ignored.
/// If `path` is relative, it is resolved against the directory given by `fd`.
///
/// The corresponding C function is `fstatat()`.
@_alwaysEmitIntoClient
public init(
_ path: UnsafePointer<CChar>,
relativeTo fd: FileDescriptor,
flags: Stat.Flags,
retryOnInterrupt: Bool = true
) throws(Errno) {
self.rawValue = try Self._fstatat(
path,
relativeTo: fd.rawValue,
flags: flags,
retryOnInterrupt: retryOnInterrupt
).get()
}
@usableFromInline
internal static func _fstatat(
_ path: UnsafePointer<CChar>,
relativeTo fd: FileDescriptor.RawValue,
flags: Stat.Flags,
retryOnInterrupt: Bool
) -> Result<CInterop.Stat, Errno> {
var result = CInterop.Stat()
return nothingOrErrno(retryOnInterrupt: retryOnInterrupt) {
system_fstatat(fd, path, &result, flags.rawValue)
}.map { result }
}
// MARK: Properties
/// ID of device containing file
///
/// The corresponding C property is `st_dev`.
@_alwaysEmitIntoClient
public var deviceID: DeviceID {
get { DeviceID(rawValue: numericCast(rawValue.st_dev)) }
set { rawValue.st_dev = numericCast(newValue.rawValue) }
}
/// Inode number
///
/// The corresponding C property is `st_ino`.
@_alwaysEmitIntoClient
public var inode: Inode {
get { Inode(rawValue: numericCast(rawValue.st_ino)) }
set { rawValue.st_ino = numericCast(newValue.rawValue) }
}
/// File mode
///
/// The corresponding C property is `st_mode`.
@_alwaysEmitIntoClient
public var mode: FileMode {
get { FileMode(rawValue: numericCast(rawValue.st_mode)) }
set { rawValue.st_mode = numericCast(newValue.rawValue) }
}
/// File type for the given mode
///
/// - Note: This property is equivalent to `mode.type`. Modifying this
/// property will update the underlying `st_mode` accordingly.
@_alwaysEmitIntoClient
public var type: FileType {
get { mode.type }
set {
var newMode = mode
newMode.type = newValue
mode = newMode
}
}
/// File permissions for the given mode
///
/// - Note: This property is equivalent to `mode.permissions`. Modifying
/// this property will update the underlying `st_mode` accordingly.
@_alwaysEmitIntoClient
public var permissions: FilePermissions {
get { mode.permissions }
set {
var newMode = mode
newMode.permissions = newValue
mode = newMode
}
}
/// Number of hard links
///
/// The corresponding C property is `st_nlink`.
@_alwaysEmitIntoClient
public var linkCount: Int {
get { Int(rawValue.st_nlink) }
set { rawValue.st_nlink = numericCast(newValue) }
}
/// User ID of owner
///
/// The corresponding C property is `st_uid`.
@_alwaysEmitIntoClient
public var userID: UserID {
get { UserID(rawValue: rawValue.st_uid) }
set { rawValue.st_uid = newValue.rawValue }
}
/// Group ID of owner
///
/// The corresponding C property is `st_gid`.
@_alwaysEmitIntoClient
public var groupID: GroupID {
get { GroupID(rawValue: rawValue.st_gid) }
set { rawValue.st_gid = newValue.rawValue }
}
/// Device ID (if special file)
///
/// For character or block special files, the returned `DeviceID` may have
/// meaningful major and minor values. For non-special files, this
/// property is usually meaningless and often set to 0.
///
/// The corresponding C property is `st_rdev`.
@_alwaysEmitIntoClient
public var specialDeviceID: DeviceID {
get { DeviceID(rawValue: numericCast(rawValue.st_rdev)) }
set { rawValue.st_rdev = numericCast(newValue.rawValue) }
}
/// Total size, in bytes
///
/// The semantics of this property are tied to the underlying C `st_size` field,
/// which can have file-system–dependent behavior. For example, this property
/// can return different values for a file's data fork and resource fork, and some
/// file systems report logical size rather than actual disk usage for compressed
/// or cloned files.
///
/// The corresponding C property is `st_size`.
@_alwaysEmitIntoClient
public var size: Int64 {
get { Int64(rawValue.st_size) }
set { rawValue.st_size = numericCast(newValue) }
}
/// Block size for file system I/O, in bytes
///
/// The corresponding C property is `st_blksize`.
@_alwaysEmitIntoClient
public var preferredIOBlockSize: Int {
get { Int(rawValue.st_blksize) }
set { rawValue.st_blksize = numericCast(newValue) }
}
/// Number of 512-byte blocks allocated
///
/// The semantics of this property are tied to the underlying C `st_blocks` field,
/// which can have file-system–dependent behavior.
///
/// The corresponding C property is `st_blocks`.
@_alwaysEmitIntoClient
public var blocksAllocated: Int64 {
get { Int64(rawValue.st_blocks) }
set { rawValue.st_blocks = numericCast(newValue) }
}
/// Total size allocated, in bytes
///
/// The semantics of this property are tied to the underlying C `st_blocks` field,
/// which can have file-system–dependent behavior.
///
/// - Note: Calculated as `512 * blocksAllocated`.
@_alwaysEmitIntoClient
public var sizeAllocated: Int64 {
512 * blocksAllocated
}
// NOTE: "st_" property names are used for the `timespec` properties so
// we can reserve `accessTime`, `modificationTime`, etc. for potential
// `UTCClock.Instant` properties in the future.
/// Time of last access, given as a C `timespec` since the Epoch.
///
/// The corresponding C property is `st_atim` (or `st_atimespec` on Darwin).
@_alwaysEmitIntoClient
public var st_atim: timespec {
get {
#if SYSTEM_PACKAGE_DARWIN
rawValue.st_atimespec
#else
rawValue.st_atim
#endif
}
set {
#if SYSTEM_PACKAGE_DARWIN
rawValue.st_atimespec = newValue
#else
rawValue.st_atim = newValue
#endif
}
}
/// Time of last modification, given as a C `timespec` since the Epoch.
///
/// The corresponding C property is `st_mtim` (or `st_mtimespec` on Darwin).
@_alwaysEmitIntoClient
public var st_mtim: timespec {
get {
#if SYSTEM_PACKAGE_DARWIN
rawValue.st_mtimespec
#else
rawValue.st_mtim
#endif
}
set {
#if SYSTEM_PACKAGE_DARWIN
rawValue.st_mtimespec = newValue
#else
rawValue.st_mtim = newValue
#endif
}
}
/// Time of last status (inode) change, given as a C `timespec` since the Epoch.
///
/// The corresponding C property is `st_ctim` (or `st_ctimespec` on Darwin).
@_alwaysEmitIntoClient
public var st_ctim: timespec {
get {
#if SYSTEM_PACKAGE_DARWIN
rawValue.st_ctimespec
#else
rawValue.st_ctim
#endif
}
set {
#if SYSTEM_PACKAGE_DARWIN
rawValue.st_ctimespec = newValue
#else
rawValue.st_ctim = newValue
#endif
}
}
#if SYSTEM_PACKAGE_DARWIN || os(FreeBSD)
/// Time of file creation, given as a C `timespec` since the Epoch.
///
/// The corresponding C property is `st_birthtim` (or `st_birthtimespec` on Darwin).
/// - Note: Only available on Darwin and FreeBSD.
@_alwaysEmitIntoClient
public var st_birthtim: timespec {
get {
#if SYSTEM_PACKAGE_DARWIN
rawValue.st_birthtimespec
#else
rawValue.st_birthtim
#endif
}
set {
#if SYSTEM_PACKAGE_DARWIN
rawValue.st_birthtimespec = newValue
#else
rawValue.st_birthtim = newValue
#endif
}
}
#endif
#if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) || os(OpenBSD)
/// File flags
///
/// The corresponding C property is `st_flags`.
/// - Note: Only available on Darwin, FreeBSD, and OpenBSD.
@_alwaysEmitIntoClient
public var flags: FileFlags {
get { FileFlags(rawValue: rawValue.st_flags) }
set { rawValue.st_flags = newValue.rawValue }
}
/// File generation number
///
/// The file generation number may be used to distinguish between different
/// files that have used the same inode over time.
///
/// The corresponding C property is `st_gen`.
/// - Note: Only available on Darwin, FreeBSD, and OpenBSD. The underlying C
/// field is 32-bit on Darwin and OpenBSD, and 64-bit on FreeBSD.
@_alwaysEmitIntoClient
public var generationNumber: UInt64 {
get { UInt64(rawValue.st_gen) }
set { rawValue.st_gen = numericCast(newValue) }
}
#endif
}
// MARK: - Equatable and Hashable
@available(System 1.7.0, *)
extension Stat: Equatable {
/// Compares the meaningful file-metadata fields of two `Stat` values.
///
/// Alignment padding and platform reserved/"spare" fields are not compared.
public static func == (lhs: Self, rhs: Self) -> Bool {
guard lhs.rawValue.st_dev == rhs.rawValue.st_dev,
lhs.rawValue.st_ino == rhs.rawValue.st_ino,
lhs.rawValue.st_mode == rhs.rawValue.st_mode,
lhs.rawValue.st_nlink == rhs.rawValue.st_nlink,
lhs.rawValue.st_uid == rhs.rawValue.st_uid,
lhs.rawValue.st_gid == rhs.rawValue.st_gid,
lhs.rawValue.st_rdev == rhs.rawValue.st_rdev,
lhs.rawValue.st_size == rhs.rawValue.st_size,
lhs.rawValue.st_blksize == rhs.rawValue.st_blksize,
lhs.rawValue.st_blocks == rhs.rawValue.st_blocks,
lhs.st_atim.tv_sec == rhs.st_atim.tv_sec,
lhs.st_atim.tv_nsec == rhs.st_atim.tv_nsec,
lhs.st_mtim.tv_sec == rhs.st_mtim.tv_sec,
lhs.st_mtim.tv_nsec == rhs.st_mtim.tv_nsec,
lhs.st_ctim.tv_sec == rhs.st_ctim.tv_sec,
lhs.st_ctim.tv_nsec == rhs.st_ctim.tv_nsec else {
return false
}
#if SYSTEM_PACKAGE_DARWIN || os(FreeBSD)
guard lhs.st_birthtim.tv_sec == rhs.st_birthtim.tv_sec,
lhs.st_birthtim.tv_nsec == rhs.st_birthtim.tv_nsec else {
return false
}
#endif
#if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) || os(OpenBSD)
guard lhs.rawValue.st_flags == rhs.rawValue.st_flags,
lhs.rawValue.st_gen == rhs.rawValue.st_gen else {
return false
}
#endif
return true
}
}
@available(System 1.7.0, *)
extension Stat: Hashable {
/// Hashes the meaningful file-metadata fields of a `Stat` struct.
///
/// These are the same fields compared by `==`, fed in the same order.
/// Alignment padding and platform reserved/"spare" fields are not hashed.
public func hash(into hasher: inout Hasher) {
hasher.combine(rawValue.st_dev)
hasher.combine(rawValue.st_ino)
hasher.combine(rawValue.st_mode)
hasher.combine(rawValue.st_nlink)
hasher.combine(rawValue.st_uid)
hasher.combine(rawValue.st_gid)
hasher.combine(rawValue.st_rdev)
hasher.combine(rawValue.st_size)
hasher.combine(rawValue.st_blksize)
hasher.combine(rawValue.st_blocks)
hasher.combine(st_atim.tv_sec)
hasher.combine(st_atim.tv_nsec)
hasher.combine(st_mtim.tv_sec)
hasher.combine(st_mtim.tv_nsec)
hasher.combine(st_ctim.tv_sec)
hasher.combine(st_ctim.tv_nsec)
#if SYSTEM_PACKAGE_DARWIN || os(FreeBSD)
hasher.combine(st_birthtim.tv_sec)
hasher.combine(st_birthtim.tv_nsec)
#endif
#if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) || os(OpenBSD)
hasher.combine(rawValue.st_flags)
hasher.combine(rawValue.st_gen)
#endif
}
}
// MARK: - CustomStringConvertible and CustomDebugStringConvertible
// MARK: - FileDescriptor Extensions
@available(System 1.7.0, *)
extension FileDescriptor {
/// Creates a `Stat` struct for the file referenced by this `FileDescriptor`.
///
/// The corresponding C function is `fstat()`.
@_alwaysEmitIntoClient
public func stat(
retryOnInterrupt: Bool = true
) throws(Errno) -> Stat {
try Stat(self, retryOnInterrupt: retryOnInterrupt)
}
}
// MARK: - FilePath Extensions
@available(System 1.7.0, *)
extension FilePath {
/// Creates a `Stat` struct for the file referenced by this `FilePath`.
///
/// `followTargetSymlink` determines the behavior if `path` ends with a symbolic link.
/// By default, `followTargetSymlink` is `true` and this initializer behaves like `stat()`.
/// If `followTargetSymlink` is set to `false`, this initializer behaves like `lstat()` and
/// returns information about the symlink itself.
///
/// The corresponding C function is `stat()` or `lstat()` as described above.
@_alwaysEmitIntoClient
public func stat(
followTargetSymlink: Bool = true,
retryOnInterrupt: Bool = true
) throws(Errno) -> Stat {
try Stat(self, followTargetSymlink: followTargetSymlink, retryOnInterrupt: retryOnInterrupt)
}
/// Creates a `Stat` struct for the file referenced by this `FilePath` using the given `Flags`.
///
/// If `path` is relative, it is resolved against the current working directory.
///
/// The corresponding C function is `fstatat()`.
@_alwaysEmitIntoClient
public func stat(
flags: Stat.Flags,
retryOnInterrupt: Bool = true
) throws(Errno) -> Stat {
try Stat(self, flags: flags, retryOnInterrupt: retryOnInterrupt)
}
/// Creates a `Stat` struct for the file referenced by this `FilePath` using the given `Flags`,
/// including a `FileDescriptor` to resolve a relative path.
///
/// If `path` is absolute (starts with a forward slash), then `fd` is ignored.
/// If `path` is relative, it is resolved against the directory given by `fd`.
///
/// The corresponding C function is `fstatat()`.
@_alwaysEmitIntoClient
public func stat(
relativeTo fd: FileDescriptor,
flags: Stat.Flags,
retryOnInterrupt: Bool = true
) throws(Errno) -> Stat {
try Stat(self, relativeTo: fd, flags: flags, retryOnInterrupt: retryOnInterrupt)
}
}
#endif // !os(Windows)