Fields

read: bool = false,

Whether the file will be created with read access.

truncate: bool = true,

If the file already exists, and is a regular file, and the access mode allows writing, it will be truncated to length 0.

exclusive: bool = false,

Ensures that this open call creates the file, otherwise causes error.PathAlreadyExists to be returned.

lock: Lock = .none,

Open the file with an advisory lock to coordinate with other processes accessing it at the same time. An exclusive lock will prevent other processes from acquiring a lock. A shared lock will prevent other processes from acquiring a exclusive lock, but does not prevent other process from getting their own shared locks.

The lock is advisory, except on Linux in very specific circumstances1. This means that a process that does not respect the locking API can still get access to the file, despite the lock.

On these operating systems, the lock is acquired atomically with opening the file:

  • Darwin
  • DragonFlyBSD
  • FreeBSD
  • Haiku
  • NetBSD
  • OpenBSD On these operating systems, the lock is acquired via a separate syscall after opening the file:
  • Linux
  • Windows
lock_nonblocking: bool = false,

Sets whether or not to wait until the file is locked to return. If set to true, error.WouldBlock will be returned. Otherwise, the file will wait until the file is available to proceed. In async I/O mode, non-blocking at the OS level is determined by intended_io_mode, and true means error.WouldBlock is returned, and false means error.WouldBlock is handled by the event loop.

For POSIX systems this is the file system mode the file will be created with. On other systems this is always 0.

intended_io_mode: io.ModeOverride = io.default_mode,

Setting this to .blocking prevents O.NONBLOCK from being passed even if std.io.is_async. It allows the use of nosuspend when calling functions related to opening the file, reading, writing, and locking.