<!--
{
  "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_create(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "c:@F@xpc_fd_create"
  },
  "title" : "xpc_fd_create(_:)"
}
-->

# xpc_fd_create(_:)

Creates an XPC object that represents a POSIX file descriptor.

```
func xpc_fd_create(_ fd: Int32) -> xpc_object_t?
```

## Parameters

`fd`

The file descriptor which is to be boxed.

## Return Value

A new file descriptor object. `NULL` if sufficient memory could not be allocated or if the given file descriptor was not valid.

## Discussion

This method performs the equivalent of a `dup(2)` on the descriptor, so it is safe to call `close(2)` on the descriptor after boxing it with a file descriptor object.

> Important:
> Pointer equality is the ONLY valid test for equality between two file descriptor objects. There is no reliable way to determine whether two file descriptors refer to the same inode with the same capabilities, so two file descriptor objects created from the same underlying file descriptor number will not compare equally with ``doc://com.apple.xpc/documentation/XPC/xpc_equal(_:_:)``. This is also true of a file descriptor object created using ``doc://com.apple.xpc/documentation/XPC/xpc_copy(_:)`` and the original.

This also implies that two collections containing file descriptor objects cannot be equal unless the exact same object was inserted into both.

---

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)