Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Struct

OpenFileOptions

Public Struct
std.Io.Dir.OpenFileOptions
pub const OpenFileOptions = struct

Fields

mode: Mode = .read_only
allow_directory: bool = true

Determines the behavior when opening a path that refers to a directory.

If set to true, directories may be opened, but error.IsDir is still possible in certain scenarios, e.g. attempting to open a directory with write permissions.

If set to false, error.IsDir will always be returned when opening a directory.

When set to false:

  • On Windows, the behavior is implemented without any extra syscalls.
  • On other operating systems, the behavior is implemented with an additional fstat syscall.
path_only: bool = false

Indicates intent for only some operations to be performed on this opened file:

  • close
  • stat On Linux and FreeBSD, this corresponds to std.posix.O.PATH.
lock: File.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 circumstances[1]. 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

[1]: https://www.kernel.org/doc/Documentation/filesystems/mandatory-locking.txt

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.

allow_ctty: bool = false

Set this to allow the opened file to automatically become the controlling TTY for the current process.

follow_symlinks: bool = true
resolve_beneath: bool = false

If supported by the operating system, attempted path resolution that would escape the directory instead returns error.AccessDenied. If unsupported, this option is ignored.

Types

Functions

pub fn isRead(self: OpenFileOptions) bool
pub fn isWrite(self: OpenFileOptions) bool

File

Io/Dir.zig:501
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
pub const OpenFileOptions = struct {
    mode: Mode = .read_only,
    /// Determines the behavior when opening a path that refers to a directory.
    ///
    /// If set to true, directories may be opened, but `error.IsDir` is still
    /// possible in certain scenarios, e.g. attempting to open a directory with
    /// write permissions.
    ///
    /// If set to false, `error.IsDir` will always be returned when opening a directory.
    ///
    /// When set to false:
    /// * On Windows, the behavior is implemented without any extra syscalls.
    /// * On other operating systems, the behavior is implemented with an additional
    ///   `fstat` syscall.
    allow_directory: bool = true,
    /// Indicates intent for only some operations to be performed on this
    /// opened file:
    /// * `close`
    /// * `stat`
    /// On Linux and FreeBSD, this corresponds to `std.posix.O.PATH`.
    path_only: bool = false,
    /// 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 circumstances[1].
    /// 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
    ///
    /// [1]: https://www.kernel.org/doc/Documentation/filesystems/mandatory-locking.txt
    lock: File.Lock = .none,
    /// 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.
    lock_nonblocking: bool = false,
    /// Set this to allow the opened file to automatically become the
    /// controlling TTY for the current process.
    allow_ctty: bool = false,
    follow_symlinks: bool = true,
    /// If supported by the operating system, attempted path resolution that
    /// would escape the directory instead returns `error.AccessDenied`. If
    /// unsupported, this option is ignored.
    resolve_beneath: bool = false,

    pub const Mode = enum { read_only, write_only, read_write };

    pub fn isRead(self: OpenFileOptions) bool {
        return self.mode != .write_only;
    }

    pub fn isWrite(self: OpenFileOptions) bool {
        return self.mode != .read_only;
    }
}