| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6048421 commit a16f0f4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,8 +56,20 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) { | |||
| 56 | 56 | ||
| 57 | 57 | { | |
| 58 | 58 | Mutex::ScopedLock lock(per_process::env_var_mutex); | |
| 59 | - if (const char* value = getenv(key)) { | ||
| 60 | - *text = value; | ||
| 59 | + | ||
| 60 | + size_t init_sz = 256; | ||
| 61 | + MaybeStackBuffer<char, 256> val; | ||
| 62 | + int ret = uv_os_getenv(key, *val, &init_sz); | ||
| 63 | + | ||
| 64 | + if (ret == UV_ENOBUFS) { | ||
| 65 | + // Buffer is not large enough, reallocate to the updated init_sz | ||
| 66 | + // and fetch env value again. | ||
| 67 | + val.AllocateSufficientStorage(init_sz); | ||
| 68 | + ret = uv_os_getenv(key, *val, &init_sz); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + if (ret >= 0) { // Env key value fetch success. | ||
| 72 | + *text = *val; | ||
| 61 | 73 | return true; | |
| 62 | 74 | } | |
| 63 | 75 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + // Flags: --expose-internals | ||
| 3 | + require('../common'); | ||
| 4 | + const { getOptionValue } = require('internal/options'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const cp = require('child_process'); | ||
| 7 | + | ||
| 8 | + const expected_redirect_value = 'foó'; | ||
| 9 | + | ||
| 10 | + if (process.argv.length === 2) { | ||
| 11 | + const NODE_OPTIONS = `--redirect-warnings=${expected_redirect_value}`; | ||
| 12 | + const result = cp.spawnSync(process.argv0, | ||
| 13 | + ['--expose-internals', __filename, 'test'], | ||
| 14 | + { | ||
| 15 | + env: { | ||
| 16 | + ...process.env, | ||
| 17 | + NODE_OPTIONS | ||
| 18 | + }, | ||
| 19 | + stdio: 'inherit' | ||
| 20 | + }); | ||
| 21 | + assert.strictEqual(result.status, 0); | ||
| 22 | + } else { | ||
| 23 | + const redirect_value = getOptionValue('--redirect-warnings'); | ||
| 24 | + console.log(`--redirect-warings=${redirect_value}`); | ||
| 25 | + assert.strictEqual(redirect_value, expected_redirect_value); | ||
| 26 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments