|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2018 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +'use strict'; |
| 20 | + |
| 21 | +// MAIN // |
| 22 | + |
| 23 | +/** |
| 24 | +* Checks whether the built-in `process.umask` exhibits expected behavior. |
| 25 | +* |
| 26 | +* ## Notes |
| 27 | +* |
| 28 | +* - In certain environments on Windows, `process.umask` does not seem to behave as expected (e.g., a mask cannot be set). This function is indicated to "sniff" this behavior. |
| 29 | +* |
| 30 | +* @private |
| 31 | +* @returns {boolean} boolean indicating whether `process.umask` exhibits expected behavior |
| 32 | +*/ |
| 33 | +function check() { |
| 34 | + var MASK; |
| 35 | + var mask; |
| 36 | + var bool; |
| 37 | + var old; |
| 38 | + var i; |
| 39 | + |
| 40 | + MASK = process.umask(); |
| 41 | + bool = true; |
| 42 | + |
| 43 | + for ( i = 100; i < 200; i++ ) { |
| 44 | + old = process.umask(); |
| 45 | + |
| 46 | + // Should return an integer-valued number: |
| 47 | + if ( typeof old !== 'number' ) { |
| 48 | + bool = false; |
| 49 | + break; |
| 50 | + } |
| 51 | + |
| 52 | + // Attempt to update the mask: |
| 53 | + mask = process.umask( i ); |
| 54 | + |
| 55 | + // Should have returned the previous mask: |
| 56 | + if ( mask !== old ) { |
| 57 | + bool = false; |
| 58 | + break; |
| 59 | + } |
| 60 | + // Should return the current mask: |
| 61 | + if ( process.umask() !== i ) { |
| 62 | + bool = false; |
| 63 | + break; |
| 64 | + } |
| 65 | + } |
| 66 | + process.umask( MASK ); // restore |
| 67 | + return bool; |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | +// EXPORTS // |
| 72 | + |
| 73 | +module.exports = check; |
0 commit comments