time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (6432B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # umask
     22 
     23 > Get/set the process mask.
     24 
     25 <section class="intro">
     26 
     27 A **mask** is a set of bits, each of which restricts how its corresponding permission is set for newly created files. On POSIX platforms, each file has a set of attributes that control who can read, write, or execute that file. Upon creating a file, file permissions must be set to an initial setting. The process mask restricts those permission settings.
     28 
     29 If the mask contains a bit set to `1`, the corresponding initial file permission is disabled. If the mask contains a bit set to `0`, the corresponding permission is left to be determined by the requesting process and the system. The process mask is thus a filter that **removes** permissions as a file is created; i.e., each bit set to a `1` removes its corresponding permission.
     30 
     31 In octal representation, a mask is a four digit number comprised as follows (using `0077` as an example):
     32 
     33 -   `0`: special permissions (setuid, setgid, sticky bit)
     34 -   `0`: (u)ser/owner permissions
     35 -   `7`: (g)roup permissions
     36 -   `7`: (o)thers/non-group permissions
     37 
     38 Octal codes correspond to the following permissions:
     39 
     40 -   `0`: read, write, execute
     41 -   `1`: read, write
     42 -   `2`: read, execute
     43 -   `3`: read
     44 -   `4`: write, execute
     45 -   `5`: write
     46 -   `6`: execute
     47 -   `7`: no permissions
     48 
     49 If provided fewer than four digits, the mask is left-padded with zeros. Note, however, that **only** the last three digits (i.e., the file permissions digits) of the mask are actually used when the mask is applied (i.e., `mask & 0777`).
     50 
     51 Permissions can be represented using the following symbolic form:
     52 
     53 ```text
     54 u=rwx,g=rwx,o=rwx
     55 ```
     56 
     57 where
     58 
     59 -   **u**: user permissions
     60 -   **g**: group permissions
     61 -   **o**: other/non-group permissions
     62 -   **r**: read
     63 -   **w**: write
     64 -   **x**: execute
     65 
     66 When setting permissions using symbolic notation, one may use a _mask expression_ of the form:
     67 
     68 ```text
     69 [<classes>]<operator><symbols>
     70 ```
     71 
     72 where `<classes>` may be a combination of
     73 
     74 -   **u**: user
     75 -   **g**: group
     76 -   **o**: other/non-group
     77 -   **a**: all
     78 
     79 `<symbols>` may be a combination of
     80 
     81 -   **r**: read
     82 -   **w**: write
     83 -   **x**: execute
     84 -   **X**: special execute
     85 -   **s**: setuid/gid on execution
     86 -   **t**: sticky
     87 
     88 and `<operator>` may be one of
     89 
     90 -   **+**: enable
     91 -   **-**: disable
     92 -   **=**: enable specified and disable unspecified permissions
     93 
     94 For example,
     95 
     96 -   `u-w`: disable user write permissions
     97 -   `u+w`: enable user write permissions
     98 -   `u=w`: enable user write permissions and disable user read and execute
     99 
    100 To specify multiple changes, one can specify a comma-separated list of mask expressions. For example,
    101 
    102 ```text
    103 u+rwx,g-x,o=r
    104 ```
    105 
    106 would enable user read, write, and execute permissions, disable group execute permissions, enable other read permissions, and disable other write and execute permissions.
    107 
    108 The `a` class indicates "all", which is the same as specifying `ugo`. This is the default class if a class is omitted when specifying permissions. For example, `+x` is equivalent to `a+x` which is equivalent to `ugo+x` which is equivalent to `u+x,g+x,o+x` and enables execution for all classes.
    109 
    110 </section>
    111 
    112 <!-- /.intro -->
    113 
    114 <section class="usage">
    115 
    116 ## Usage
    117 
    118 ```javascript
    119 var umask = require( '@stdlib/process/umask' );
    120 ```
    121 
    122 #### umask( \[mask,] \[options] )
    123 
    124 Returns the process mask.
    125 
    126 ```javascript
    127 var mask = umask();
    128 // returns <number>
    129 ```
    130 
    131 To set the process mask, provide a `mask` argument. When provided a `mask`, the function returns the previous mask value.
    132 
    133 ```javascript
    134 var mask = umask();
    135 // returns <number>
    136 
    137 var prev = umask( 0 );
    138 // returns <number>
    139 
    140 var bool = ( prev === mask );
    141 // returns true
    142 ```
    143 
    144 The `mask` argument may be either an integer value or a `string` representing the mask using symbolic notation.
    145 
    146 ```javascript
    147 var mask = umask( 'u=rwx,g=rw,o=rw' );
    148 ```
    149 
    150 The function accepts the following `options`:
    151 
    152 -   **symbolic**: `boolean` indicating whether to return the mask in symbolic notation. Default: `false`.
    153 
    154 To return the process mask in symbolic notation, set the `symbolic` option to `true`.
    155 
    156 ```javascript
    157 var opts = {
    158     'symbolic': true
    159 };
    160 
    161 // Get the mask:
    162 var mask = umask( opts );
    163 // e.g., returns 'u=rwx,g=rw,o=rw'
    164 
    165 // Set the mask:
    166 mask = umask( 0, opts );
    167 // e.g., returns 'u=rwx,g=rw,o=rw'
    168 ```
    169 
    170 </section>
    171 
    172 <!-- /.usage -->
    173 
    174 <section class="notes">
    175 
    176 ## Notes
    177 
    178 -   To set the process mask using an octal `string` (e.g., `0777`), use `parseInt` to convert the `string` to an integer value.
    179 
    180     ```javascript
    181     umask( parseInt( '0777', 8 ) );
    182     ```
    183 
    184 -   See [umask(2)][umask].
    185 
    186 </section>
    187 
    188 <!-- /.notes -->
    189 
    190 <section class="examples">
    191 
    192 ## Examples
    193 
    194 <!-- eslint no-undef: "error" -->
    195 
    196 ```javascript
    197 var lpad = require( '@stdlib/string/left-pad' );
    198 var umask = require( '@stdlib/process/umask' );
    199 
    200 var mask;
    201 var opts;
    202 
    203 // Print the process mask as an integer:
    204 mask = umask();
    205 console.log( mask.toString() );
    206 
    207 // Print the process mask as an octal string:
    208 console.log( lpad( mask.toString(), 4, '0' ) );
    209 
    210 // Print the process mask using symbolic notation:
    211 opts = {
    212     'symbolic': true
    213 };
    214 console.log( umask( opts ) );
    215 ```
    216 
    217 </section>
    218 
    219 <!-- /.examples -->
    220 
    221 * * *
    222 
    223 <section class="cli">
    224 
    225 ## CLI
    226 
    227 <section class="usage">
    228 
    229 ### Usage
    230 
    231 ```text
    232 Usage: umask [options]
    233 
    234 Options:
    235 
    236   -h,    --help                Print this message.
    237   -V,    --version             Print the package version.
    238   -p,    --print               Print the mask command.
    239   -S,    --symbolic            Print the mask using symbolic notation.
    240 ```
    241 
    242 </section>
    243 
    244 <!-- /.usage -->
    245 
    246 <section class="examples">
    247 
    248 ### Examples
    249 
    250 ```bash
    251 $ umask
    252 ```
    253 
    254 To print the mask in command format, set the `-p` flag.
    255 
    256 ```bash
    257 $ umask -p
    258 ```
    259 
    260 </section>
    261 
    262 <!-- /.examples -->
    263 
    264 </section>
    265 
    266 <!-- /.cli -->
    267 
    268 <section class="links">
    269 
    270 [umask]: http://man7.org/linux/man-pages/man2/umask.2.html
    271 
    272 </section>
    273 
    274 <!-- /.links -->