Instance MethodSystemPackage

    duplicate(as:retryOnInterrupt:)

    Duplicate this file descriptor and return the newly created copy.

    func duplicate(as target: FileDescriptor? = nil, retryOnInterrupt: Bool = true) throws -> FileDescriptor

    Parameters

    `target`

    The desired target file descriptor, or nil, in which case the copy is assigned to the file descriptor with the lowest raw value that is not currently in use by the process.

    retryOnInterrupt

    Whether to retry the write operation if it throws Errno.interrupted. The default is true. Pass false to try only once and throw an error upon interruption.

    Returns

    The new file descriptor.

    Overview

    If the target descriptor is already in use, then it is first deallocated as if a close(2) call had been done first.

    File descriptors are merely references to some underlying system resource. The system does not distinguish between the original and the new file descriptor in any way. For example, read, write and seek operations on one of them also affect the logical file position in the other, and append mode, non-blocking I/O and asynchronous I/O options are shared between the references. If a separate pointer into the file is desired, a different object reference to the file must be obtained by issuing an additional call to open.

    However, each file descriptor maintains its own close-on-exec flag.

    The corresponding C functions are dup and dup2.