@@ -319,4 +319,57 @@ extension FileDescriptor {
319319 }
320320 #endif
321321 }
322+
323+ /// Rename a file or directory relative to directory file descriptors
324+ ///
325+ /// - Parameters:
326+ /// - oldPath: The relative location of the file or directory to rename.
327+ /// - newDirFd: The directory file descriptor for the new path.
328+ /// - newPath: The relative destination path to which to rename the file or directory.
329+ ///
330+ /// The corresponding C function is `renameat`.
331+ @_alwaysEmitIntoClient
332+ public func rename(
333+ at oldPath: FilePath ,
334+ to newDirFd: FileDescriptor ,
335+ at newPath: FilePath
336+ ) throws {
337+ try oldPath. withPlatformString { cOldPath in
338+ try newPath. withPlatformString { cNewPath in
339+ try _rename ( at: cOldPath, to: newDirFd, at: cNewPath) . get ( )
340+ }
341+ }
342+ }
343+
344+ /// Rename a file or directory relative to directory file descriptors
345+ ///
346+ /// - Parameters:
347+ /// - oldPath: The relative location of the file or directory to rename.
348+ /// - newDirFd: The directory file descriptor for the new path.
349+ /// - newPath: The relative destination path to which to rename the file or directory.
350+ ///
351+ /// The corresponding C function is `renameat`.
352+ @_alwaysEmitIntoClient
353+ public func rename(
354+ at oldPath: UnsafePointer < CInterop . PlatformChar > ,
355+ to newDirFd: FileDescriptor ,
356+ at newPath: UnsafePointer < CInterop . PlatformChar >
357+ ) throws {
358+ try _rename ( at: oldPath, to: newDirFd, at: newPath) . get ( )
359+ }
360+
361+ @usableFromInline
362+ internal func _rename(
363+ at oldPath: UnsafePointer < CInterop . PlatformChar > ,
364+ to newDirFd: FileDescriptor ,
365+ at newPath: UnsafePointer < CInterop . PlatformChar >
366+ ) -> Result < ( ) , Errno > {
367+ #if os(Windows)
368+ return . failure( Errno ( rawValue: ERROR_NOT_SUPPORTED) )
369+ #else
370+ return nothingOrErrno ( retryOnInterrupt: false ) {
371+ system_renameat ( self . rawValue, oldPath, newDirFd. rawValue, newPath)
372+ }
373+ #endif
374+ }
322375}
0 commit comments