github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/experimental/sys/oflag.go (about)

     1  package sys
     2  
     3  // Oflag are flags used for FS.OpenFile. Values, including zero, should not be
     4  // interpreted numerically. Instead, use by constants prefixed with 'O_' with
     5  // special casing noted below.
     6  //
     7  // # Notes
     8  //
     9  //   - O_RDONLY, O_RDWR and O_WRONLY are mutually exclusive, while the other
    10  //     flags can coexist bitwise.
    11  //   - This is like `flag` in os.OpenFile and `oflag` in POSIX. See
    12  //     https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
    13  type Oflag uint32
    14  
    15  // This is a subset of oflags to reduce implementation burden. `wasip1` splits
    16  // these across `oflags` and `fdflags`. We can't rely on the Go `os` package,
    17  // as it is missing some values. Any flags added will be defined in POSIX
    18  // order, as needed by functions that explicitly document accepting them.
    19  //
    20  // https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-oflags-flagsu16
    21  // https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-fdflags-flagsu16
    22  const (
    23  	// O_RDONLY is like os.O_RDONLY
    24  	O_RDONLY Oflag = iota
    25  
    26  	// O_RDWR is like os.O_RDWR
    27  	O_RDWR
    28  
    29  	// O_WRONLY is like os.O_WRONLY
    30  	O_WRONLY
    31  
    32  	// Define bitflags as they are in POSIX `open`: alphabetically
    33  
    34  	// O_APPEND is like os.O_APPEND
    35  	O_APPEND Oflag = 1 << iota
    36  
    37  	// O_CREAT is link os.O_CREATE
    38  	O_CREAT
    39  
    40  	// O_DIRECTORY is defined on some platforms as syscall.O_DIRECTORY.
    41  	//
    42  	// Note: This ensures that the opened file is a directory. Those emulating
    43  	// on platforms that don't support the O_DIRECTORY, can double-check the
    44  	// result with File.IsDir (or stat) and err if not a directory.
    45  	O_DIRECTORY
    46  
    47  	// O_DSYNC is defined on some platforms as syscall.O_DSYNC.
    48  	O_DSYNC
    49  
    50  	// O_EXCL is defined on some platforms as syscall.O_EXCL.
    51  	O_EXCL
    52  
    53  	// O_NOFOLLOW is defined on some platforms as syscall.O_NOFOLLOW.
    54  	//
    55  	// Note: This allows programs to ensure that if the opened file is a
    56  	// symbolic link, the link itself is opened instead of its target.
    57  	O_NOFOLLOW
    58  
    59  	// O_NONBLOCK is defined on some platforms as syscall.O_NONBLOCK.
    60  	O_NONBLOCK
    61  
    62  	// O_RSYNC is defined on some platforms as syscall.O_RSYNC.
    63  	O_RSYNC
    64  
    65  	// O_SYNC is defined on some platforms as syscall.O_SYNC.
    66  	O_SYNC
    67  
    68  	// O_TRUNC is defined on some platforms as syscall.O_TRUNC.
    69  	O_TRUNC
    70  )