MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_setenv

Function cbm_setenv

src/foundation/compat.h:149–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147/* ── setenv / unsetenv (Windows lacks them) ──────────────────── */
148#ifdef _WIN32
149static inline int cbm_setenv(const char *name, const char *value, int overwrite) {
150 (void)overwrite;
151 if (!name || !value) {
152 return EINVAL;
153 }
154 int name_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, name, -1, NULL, 0);
155 int value_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, value, -1, NULL, 0);
156 wchar_t *wide_name =
157 name_chars > 0 ? (wchar_t *)malloc((size_t)name_chars * sizeof(*wide_name)) : NULL;
158 wchar_t *wide_value =
159 value_chars > 0 ? (wchar_t *)malloc((size_t)value_chars * sizeof(*wide_value)) : NULL;
160 bool converted =
161 wide_name && wide_value &&
162 MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, name, -1, wide_name, name_chars) > 0 &&
163 MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, value, -1, wide_value, value_chars) > 0;
164 if (!converted) {
165 free(wide_name);
166 free(wide_value);
167 return EINVAL;
168 }
169 /* Keep the CRT's narrow environment useful for legacy getenv callers,
170 * then repair the process-wide Windows environment with the actual UTF-16
171 * value. _putenv_s alone routes UTF-8 path bytes through the active ANSI
172 * code page, which corrupts non-ASCII cache roots inherited by children. */
173 int status = _putenv_s(name, value);
174 if (status == 0 && !SetEnvironmentVariableW(wide_name, wide_value)) {
175 status = EINVAL;
176 }
177 free(wide_name);
178 free(wide_value);
179 return status;
180}
181static inline int cbm_unsetenv(const char *name) {
182 if (!name) {
183 return EINVAL;

Callers 15

main_build_identityFunction · 0.85
worker_set_local_envFunction · 0.85
restore_test_envFunction · 0.85
test_cli.cFile · 0.85
cli_scope_fixture_startFunction · 0.85
cli_scope_installFunction · 0.85
cli_scope_fixture_finishFunction · 0.85
openhands_fixture_openFunction · 0.85

Calls

no outgoing calls

Tested by 15

restore_test_envFunction · 0.68
cli_scope_fixture_startFunction · 0.68
cli_scope_installFunction · 0.68
cli_scope_fixture_finishFunction · 0.68
openhands_fixture_openFunction · 0.68
hl_run_hookFunction · 0.68
fixture_openFunction · 0.68
restore_envFunction · 0.68
git_env_hook_enterFunction · 0.68