<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "System",
  "identifier" : "/documentation/System/FileDescriptor",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "System"
    ],
    "preciseIdentifier" : "s:6System14FileDescriptorV"
  },
  "title" : "FileDescriptor"
}
-->

# FileDescriptor

An abstract handle to an input or output data resource,
such as a file or a socket.

```
@frozen struct FileDescriptor
```

## Overview

You are responsible for managing the lifetime and validity
of `FileDescriptor` values,
in the same way as you manage a raw C file handle.

## Topics

### Creating a File Descriptor

[`init(rawValue:)`](/documentation/System/FileDescriptor/init(rawValue:))

Creates a strongly-typed file handle from a raw C file handle.

[`rawValue`](/documentation/System/FileDescriptor/rawValue)

The raw C file handle.

### Opening a File

[`open(_:_:options:permissions:retryOnInterrupt:)`](/documentation/System/FileDescriptor/open(_:_:options:permissions:retryOnInterrupt:)-4ql4b)

[`open(_:_:options:permissions:retryOnInterrupt:)`](/documentation/System/FileDescriptor/open(_:_:options:permissions:retryOnInterrupt:)-5t3xn)

[`FileDescriptor.AccessMode`](/documentation/System/FileDescriptor/AccessMode)

The desired read and write access for a newly opened file.

[`FileDescriptor.OpenOptions`](/documentation/System/FileDescriptor/OpenOptions)

Options that specify behavior for a newly-opened file.

### Reading From a File

[`read(into:retryOnInterrupt:)`](/documentation/System/FileDescriptor/read(into:retryOnInterrupt:))

Reads bytes at the current file offset into a buffer.

[`read(fromAbsoluteOffset:into:retryOnInterrupt:)`](/documentation/System/FileDescriptor/read(fromAbsoluteOffset:into:retryOnInterrupt:))

Reads bytes at the specified offset into a buffer.

### Changing a File’s Offset

[`seek(offset:from:)`](/documentation/System/FileDescriptor/seek(offset:from:))

Repositions the offset for the given file descriptor.

[`FileDescriptor.SeekOrigin`](/documentation/System/FileDescriptor/SeekOrigin)

Options for specifying what a file descriptor’s offset is relative to.

### Writing To A File

[`write(_:retryOnInterrupt:)`](/documentation/System/FileDescriptor/write(_:retryOnInterrupt:))

Writes the contents of a buffer at the current file offset.

[`write(toAbsoluteOffset:_:retryOnInterrupt:)`](/documentation/System/FileDescriptor/write(toAbsoluteOffset:_:retryOnInterrupt:))

Writes the contents of a buffer at the specified offset.

[`writeAll(_:)`](/documentation/System/FileDescriptor/writeAll(_:))

Writes a sequence of bytes to the current offset
and then updates the offset.

[`writeAll(toAbsoluteOffset:_:)`](/documentation/System/FileDescriptor/writeAll(toAbsoluteOffset:_:))

Writes a sequence of bytes to the given offset.

### Closing a File

[`close()`](/documentation/System/FileDescriptor/close())

Deletes a file descriptor.

[`closeAfter(_:)`](/documentation/System/FileDescriptor/closeAfter(_:))

Runs a closure and then closes the file descriptor, even if an error occurs.

### Encoding File Descriptors

### Comparing File Descriptors



---

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)