@@ -31,6 +31,21 @@ extension FileDescriptor {
3131
3232// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
3333extension FilePath {
34+ /// Obtain information about the file pointed to by the FilePath.
35+ ///
36+ /// - Parameters:
37+ /// - followSymlinks: Whether to follow symlinks.
38+ /// The default is `true`.
39+ /// - retryOnInterrupt: Whether to retry the read operation
40+ /// if it throws ``Errno/interrupted``.
41+ /// The default is `true`.
42+ /// Pass `false` to try only once and throw an error upon interruption.
43+ /// - Returns: A `FileStatus` for the file pointed to by FilePath.
44+ ///
45+ /// Read, write or execute permission of the pointed to file is not required,
46+ /// but all intermediate directories must be searchable.
47+ ///
48+ /// The corresponding C functions are `stat` and `lstat`.
3449 @_alwaysEmitIntoClient
3550 public func stat(
3651 followSymlinks: Bool = true ,
@@ -48,7 +63,7 @@ extension FilePath {
4863 retryOnInterrupt: Bool
4964 ) -> Result < FileStatus , Errno > {
5065 var result = CInterop . Stat ( )
51- let _stat = followSymlinks ? SystemPackage . _stat : _lstat
66+ let _stat = followSymlinks ? system_stat : system_lstat
5267 return withPlatformString { ptr in
5368 nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
5469 _stat ( ptr, & result)
@@ -67,7 +82,7 @@ extension FileDescriptor {
6782 internal func fstat( retryOnInterrupt: Bool = true ) throws -> FileStatus {
6883 var result = CInterop . Stat ( )
6984 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
70- _fstat ( self . rawValue, & result)
85+ system_fstat ( self . rawValue, & result)
7186 } . get ( )
7287 return FileStatus ( rawValue: result)
7388 }
@@ -76,7 +91,7 @@ extension FileDescriptor {
7691 var result = CInterop . Stat ( )
7792 try path. withPlatformString { ptr in
7893 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
79- _fstatat ( self . rawValue, ptr, & result, fcntrl. rawValue)
94+ system_fstatat ( self . rawValue, ptr, & result, fcntrl. rawValue)
8095 } . get ( )
8196 }
8297 return FileStatus ( rawValue: result)
@@ -113,7 +128,7 @@ extension FilePath {
113128 followSymlinks: Bool ,
114129 retryOnInterrupt: Bool
115130 ) -> Result < Void , Errno > {
116- let _chmod = followSymlinks ? SystemPackage . _chmod : _lchmod
131+ let _chmod = followSymlinks ? system_chmod : system_lchmod
117132 return withPlatformString { ptr in
118133 nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
119134 _chmod ( ptr, permissions. rawValue)
@@ -126,15 +141,15 @@ extension FilePath {
126141extension FileDescriptor {
127142 internal func fchmod( permissions: FilePermissions , retryOnInterrupt: Bool = true ) throws {
128143 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
129- _fchmod ( self . rawValue, permissions. rawValue)
144+ system_fchmod ( self . rawValue, permissions. rawValue)
130145 } . get ( )
131146 }
132147
133148 // valid flags: AT_SYMLINK_NOFOLLOW | AT_REALDEV | AT_FDONLY
134149 internal func fchmodat( path: FilePath , permissions: FilePermissions , fcntrl: FileDescriptor . ControlFlags , retryOnInterrupt: Bool = true ) throws {
135150 try path. withPlatformString { ptr in
136151 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
137- _fchmodat ( self . rawValue, ptr, permissions. rawValue, fcntrl. rawValue)
152+ system_fchmodat ( self . rawValue, ptr, permissions. rawValue, fcntrl. rawValue)
138153 } . get ( )
139154 }
140155 }
@@ -171,7 +186,7 @@ extension FilePath {
171186 followSymlinks: Bool ,
172187 retryOnInterrupt: Bool
173188 ) -> Result < Void , Errno > {
174- let _chown = followSymlinks ? SystemPackage . _chown : _lchown
189+ let _chown = followSymlinks ? system_chown : system_lchown
175190 return withPlatformString { ptr in
176191 nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
177192 _chown ( ptr, userId, groupId)
@@ -184,14 +199,14 @@ extension FilePath {
184199extension FileDescriptor {
185200 internal func fchown( userId: CInterop . UserId , groupId: CInterop . GroupId , retryOnInterrupt: Bool = true ) throws {
186201 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
187- _fchown ( self . rawValue, userId, groupId)
202+ system_fchown ( self . rawValue, userId, groupId)
188203 } . get ( )
189204 }
190205
191206 internal func fchownat( path: FilePath , userId: CInterop . UserId , groupId: CInterop . GroupId , fcntrl: FileDescriptor . ControlFlags , retryOnInterrupt: Bool = true ) throws {
192207 try path. withPlatformString { ptr in
193208 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
194- _fchownat ( self . rawValue, ptr, userId, groupId, fcntrl. rawValue)
209+ system_fchownat ( self . rawValue, ptr, userId, groupId, fcntrl. rawValue)
195210 } . get ( )
196211 }
197212 }
@@ -225,7 +240,7 @@ extension FilePath {
225240 followSymlinks: Bool ,
226241 retryOnInterrupt: Bool
227242 ) -> Result < Void , Errno > {
228- let _chflags = followSymlinks ? SystemPackage . _chflags : _lchflags
243+ let _chflags = followSymlinks ? system_chflags : system_lchflags
229244 return withPlatformString { ptr in
230245 nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
231246 _chflags ( ptr, flags. rawValue)
@@ -238,15 +253,15 @@ extension FilePath {
238253extension FileDescriptor {
239254 internal func fchflags( flags: FileFlags , retryOnInterrupt: Bool = true ) throws {
240255 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
241- _fchflags ( self . rawValue, flags. rawValue)
256+ system_fchflags ( self . rawValue, flags. rawValue)
242257 } . get ( )
243258 }
244259
245260#if os(FreeBSD)
246261 internal func chflagsat( path: FilePath , flags: FileFlags , fcntrl: FileDescriptorControlFlags , retryOnInterrupt: Bool = true ) throws {
247262 try path. withPlatformString { ptr in
248263 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
249- _chflagsat ( self . rawValue, ptr, flags. rawValue, fcntrl. rawValue)
264+ system_chflagsat ( self . rawValue, ptr, flags. rawValue, fcntrl. rawValue)
250265 } . get ( )
251266 }
252267 }
@@ -255,23 +270,22 @@ extension FileDescriptor {
255270
256271// MARK: - umask
257272
258- // FIXME: document, shape
259- /// The umask() routine sets the process's file mode creation mask to cmask and
260- /// returns the previous value of the mask. The 9 low-order access permission
261- /// bits of cmask are used by system calls, including open(2), mkdir(2),
262- /// mkfifo(2), and mknod(2) to turn off corresponding bits requested in file
263- /// mode. (See chmod(2)). This clearing allows each user to restrict the
264- /// default access to his files.
273+ // FIXME: umask document, shape
274+ /// The umask() routine sets the process's file mode creation mask to newMask
275+ /// and returns the previous value of the mask. The bits of newMask are used by
276+ /// system calls, including open(2), mkdir(2), mkfifo(2), and mknod(2) to turn
277+ /// off corresponding bits requested in file mode. (See chmod(2)). This clearing
278+ /// allows each user to restrict the default access to their files.
265279///
266280/// The default mask value is `S_IWGRP` | `S_IWOTH` (022, write access for the
267- /// owner only). Child processes inherit the mask of the calling process.
268- @_alwaysEmitIntoClient
269- public func umask( newMask: FilePermissions ) -> FilePermissions {
270- let mode = _umask ( newMask. rawValue)
271- return FileMode ( rawValue: mode ) . permissions
272- }
281+ /// owner only). Child processes inherit the mask of the calling process.
282+ // @_alwaysEmitIntoClient
283+ // public func umask(newMask: FilePermissions) -> FilePermissions {
284+ // let oldMode = system_umask (newMask.rawValue)
285+ // return FileMode(rawValue: oldMode ).permissions
286+ // }
273287
274- // [ ] mode_t umask(mode_t)
288+ // [x ] mode_t umask(mode_t)
275289
276290// MARK: - mkfifo, mknod, mkdir
277291
@@ -300,7 +314,7 @@ extension FilePath {
300314 ) -> Result < Void , Errno > {
301315 withPlatformString { ptr in
302316 nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
303- SystemPackage . _mkfifo ( ptr, permissions. rawValue)
317+ system_mkfifo ( ptr, permissions. rawValue)
304318 }
305319 }
306320 }
@@ -326,7 +340,7 @@ extension FilePath {
326340 ) -> Result < Void , Errno > {
327341 withPlatformString { ptr in
328342 nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
329- SystemPackage . _mknod ( ptr, permissions. rawValue, device)
343+ system_mknod ( ptr, permissions. rawValue, device)
330344 }
331345 }
332346 }
@@ -349,7 +363,7 @@ extension FilePath {
349363 ) -> Result < Void , Errno > {
350364 withPlatformString { ptr in
351365 nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
352- SystemPackage . _mkdir ( ptr, permissions. rawValue)
366+ system_mkdir ( ptr, permissions. rawValue)
353367 }
354368 }
355369 }
@@ -359,7 +373,7 @@ extension FileDescriptor {
359373 internal func mkdirat( path: FilePath , permissions: FilePermissions , retryOnInterrupt: Bool = true ) throws {
360374 try path. withPlatformString { ptr in
361375 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
362- _mkdirat ( self . rawValue, ptr, permissions. rawValue)
376+ system_mkdirat ( self . rawValue, ptr, permissions. rawValue)
363377 } . get ( )
364378 }
365379 }
@@ -376,7 +390,7 @@ extension FileDescriptor {
376390 internal func futimens( accessTime: TimeSpecification , modificationTime: TimeSpecification , retryOnInterrupt: Bool = true ) throws {
377391 let times = [ accessTime. rawValue, modificationTime. rawValue]
378392 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
379- _futimens ( self . rawValue, times)
393+ system_futimens ( self . rawValue, times)
380394 } . get ( )
381395 }
382396
@@ -385,7 +399,7 @@ extension FileDescriptor {
385399 let times = [ accessTime. rawValue, modificationTime. rawValue]
386400 try path. withPlatformString { ptr in
387401 try nothingOrErrno ( retryOnInterrupt: retryOnInterrupt) {
388- _utimensat ( self . rawValue, ptr, times, fcntrl. rawValue)
402+ system_utimensat ( self . rawValue, ptr, times, fcntrl. rawValue)
389403 } . get ( )
390404 }
391405 }
0 commit comments