<!--
{
  "documentType" : "article",
  "framework" : "System",
  "identifier" : "/documentation/System/adopting-file-options",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Adopting Swift File Options"
}
-->

# Adopting Swift File Options

Migrate existing C code to Swift, using the file-operation options provided by the System module.

## Discussion

The C options for how to open a file map to Swift as follows:

- `O_RDONLY` ⟶ [`readOnly`](/documentation/System/FileDescriptor/AccessMode/readOnly)
- `O_WRONLY` ⟶ [`writeOnly`](/documentation/System/FileDescriptor/AccessMode/writeOnly)
- `O_RDWR` ⟶ [`readWrite`](/documentation/System/FileDescriptor/AccessMode/readWrite)

The C constants for specifying options when opening a file map to Swift as follows:

- `O_NONBLOCK` ⟶ [`nonBlocking`](/documentation/System/FileDescriptor/OpenOptions/nonBlocking)
- `O_APPEND` ⟶ [`append`](/documentation/System/FileDescriptor/OpenOptions/append)
- `O_CREAT` ⟶ [`create`](/documentation/System/FileDescriptor/OpenOptions/create)
- `O_TRUNC` ⟶ [`truncate`](/documentation/System/FileDescriptor/OpenOptions/truncate)
- `O_EXCL` ⟶ [`exclusiveCreate`](/documentation/System/FileDescriptor/OpenOptions/exclusiveCreate)
- `O_SHLOCK` ⟶ [`sharedLock`](/documentation/System/FileDescriptor/OpenOptions/sharedLock)
- `O_EXLOCK` ⟶ [`exclusiveLock`](/documentation/System/FileDescriptor/OpenOptions/exclusiveLock)
- `O_NOFOLLOW` ⟶ [`noFollow`](/documentation/System/FileDescriptor/OpenOptions/noFollow)
- `O_SYMLINK` ⟶ [`symlink`](/documentation/System/FileDescriptor/OpenOptions/symlink)
- `O_EVTONLY` ⟶ [`eventOnly`](/documentation/System/FileDescriptor/OpenOptions/eventOnly)
- `O_CLOEXEC` ⟶ [`closeOnExec`](/documentation/System/FileDescriptor/OpenOptions/closeOnExec)

The C constants for specify seek offsets map to Swift as follows:

- `SEEK_SET` ⟶ [`start`](/documentation/System/FileDescriptor/SeekOrigin/start)
- `SEEK_CUR` ⟶ [`current`](/documentation/System/FileDescriptor/SeekOrigin/current)
- `SEEK_END` ⟶ [`end`](/documentation/System/FileDescriptor/SeekOrigin/end)
- `SEEK_HOLE` ⟶ [`nextHole`](/documentation/System/FileDescriptor/SeekOrigin/nextHole)
- `SEEK_DATA` ⟶ [`nextData`](/documentation/System/FileDescriptor/SeekOrigin/nextData)

---

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)