1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// This file is part of yash, an extended POSIX shell.
// Copyright (C) 2024 WATANABE Yuki
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Umask built-in
//!
//! The **`umask`** built-in shows or sets the file mode creation mask.
//!
//! # Synopsis
//!
//! ```sh
//! umask [-S] [mode]
//! ```
//!
//! # Description
//!
//! The built-in shows the current file mode creation mask if no *mode* is
//! given. Otherwise, it sets the file mode creation mask to *mode*.
//!
//! # Options
//!
//! The **`-S`** (**`--symbolic`**) option causes the built-in to show the
//! current file mode creation mask in symbolic notation.
//!
//! # Operands
//!
//! *mode* is an octal integer or a symbolic notation that represents the file
//! mode creation mask. The octal number is the bitwise OR of the file mode bits
//! to be turned off when creating a file. The symbolic notation specifies the
//! file mode bits to be kept on when creating a file. The symbolic notation
//! consists of one or more clauses separated by commas. Each clause consists of
//! a (possibly empty) sequence of who symbols followed by one or more actions.
//! The who symbols are:
//!
//! - **`u`** for the user bits,
//! - **`g`** for the group bits,
//! - **`o`** for the other bits, and
//! - **`a`** for all bits.
//!
//! An action is an operator optionally followed by permission symbols. The
//! operators are:
//!
//! - **`+`** to add the permission,
//! - **`-`** to remove the permission, and
//! - **`=`** to set the permission.
//!
//! The permission symbols are:
//!
//! - one or more of:
//! - **`r`** for the read permission,
//! - **`w`** for the write permission,
//! - **`x`** for the execute permission,
//! - **`X`** for the execute permission if the execute permission is
//! already set for any who, and
//! - **`s`** for the set-user-ID-on-execution and set-group-ID-on-execution
//! bits.
//! - **`u`** for the current user permission,
//! - **`g`** for the current group permission, and
//! - **`o`** for the current other permission.
//!
//! For example, the symbolic notation `u=rwx,go+r-w`
//!
//! - sets the user bits to read, write, and execute,
//! - adds the read permission to the group and the other bits, and
//! - removes the write permission from the group and the other bits.
//!
//! # Standard output
//!
//! If no *mode* is given, the built-in prints the current file mode creation
//! mask in octal notation followed by a newline to the standard output.
//! If the `-S` option is effective, the mask is formatted in symbolic notation
//! instead.
//!
//! # Errors
//!
//! It is an error if the specified *mode* is not a valid file mode creation
//! mask.
//!
//! # Exit status
//!
//! Zero unless an error occurred.
//!
//! # Portability
//!
//! The `umask` built-in is defined in POSIX.
//!
//! POSIX does not specify the default output format used when the `-S` option is
//! not given. Our implementation, as well as many others, uses octal notation.
//!
//! This implementation ignores the `-S` option if *mode* is given. However,
//! bash prints the new mask in symbolic notation if the `-S` option and *mode*
//! are both given.
//!
//! An empty sequence of who symbols is equivalent to `a` in this implementation
//! as well as many others. However, this may not be strictly true to the POSIX
//! specification.
//!
//! The permission symbols other than `r`, `w`, and `x` are not widely supported.
//! This implementation currently ignores the `s` symbol.
use crate;
use Field;
use Mode;
use ;
/// Interpretation of command-line arguments that determine the behavior of the
/// `umask` built-in
/// Entry point of the `umask` built-in
pub async