<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/xpc_fd_dup(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "c:@F@xpc_fd_dup"
  },
  "title" : "xpc_fd_dup(_:)"
}
-->

# xpc_fd_dup(_:)

Returns a file descriptor that is equivalent to the one that the specified file descriptor object boxes.

```
func xpc_fd_dup(_ xfd: xpc_object_t) -> Int32
```

## Parameters

`xfd`

The file descriptor object which is to be examined.

## Return Value

A file descriptor that is equivalent to the one originally given to [`xpc_fd_create(_:)`](/documentation/XPC/xpc_fd_create(_:)). If the descriptor could not be created, -1 is returned.

## Discussion

Multiple invocations of [`xpc_fd_dup(_:)`](/documentation/XPC/xpc_fd_dup(_:)) will not return the same file descriptor number, but they will return descriptors that are equivalent, as though they had been created by `dup(2)`.

The caller is responsible for calling `close(2)` on the returned descriptor.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)