yash_env/system/open_flag.rs
1// This file is part of yash, an extended POSIX shell.
2// Copyright (C) 2024 WATANABE Yuki
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17//! Defines flags for configuring open file descriptions.
18
19use enumset::EnumSetType;
20
21/// File access mode of open file descriptions
22#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
23#[non_exhaustive]
24pub enum OfdAccess {
25 /// Open for reading only
26 ReadOnly,
27 /// Open for writing only
28 WriteOnly,
29 /// Open for reading and writing
30 ReadWrite,
31 /// Open for executing only (non-directory files)
32 Exec,
33 /// Open for searching only (directories)
34 Search,
35}
36
37/// Options for opening file descriptors
38///
39/// A set of `OpenFlag` values can be passed to [`open`] to configure how the
40/// file descriptor is opened. Some of the flags become the attributes of the
41/// open file description created by the `open` function.
42///
43/// [`open`]: crate::system::System::open
44#[derive(Debug, EnumSetType, Hash)]
45#[non_exhaustive]
46pub enum OpenFlag {
47 /// Always write to the end of the file
48 Append,
49 /// Close the file descriptor upon execution of an exec family function
50 CloseOnExec,
51 /// Create the file if it does not exist
52 Create,
53 /// Fail if the file is not a directory
54 Directory,
55 /// Atomically create the file if it does not exist
56 Exclusive,
57 /// Do not make the opened terminal the controlling terminal for the process
58 NoCtty,
59 /// Do not follow symbolic links
60 NoFollow,
61 /// Open the file in non-blocking mode
62 NonBlock,
63 /// Wait until the written data is physically stored on the underlying
64 /// storage device on each write
65 Sync,
66 /// Truncate the file to zero length
67 Truncate,
68}