| 165 | return status; |
| 166 | } |
| 167 | static inline int cbm_unsetenv(const char *name) { |
| 168 | if (!name) { |
| 169 | return EINVAL; |
| 170 | } |
| 171 | int name_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, name, -1, NULL, 0); |
| 172 | wchar_t *wide_name = |
| 173 | name_chars > 0 ? (wchar_t *)malloc((size_t)name_chars * sizeof(*wide_name)) : NULL; |
| 174 | if (!wide_name || |
| 175 | MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, name, -1, wide_name, name_chars) <= 0) { |
| 176 | free(wide_name); |
| 177 | return EINVAL; |
| 178 | } |
| 179 | int status = _putenv_s(name, ""); |
| 180 | if (status == 0) { |
| 181 | SetLastError(ERROR_SUCCESS); |
| 182 | if (!SetEnvironmentVariableW(wide_name, NULL) && GetLastError() != ERROR_ENVVAR_NOT_FOUND) { |
| 183 | status = EINVAL; |
| 184 | } |
| 185 | } |
| 186 | free(wide_name); |
| 187 | return status; |
| 188 | } |
| 189 | #else |
| 190 | #define cbm_setenv setenv |
| 191 | #define cbm_unsetenv unsetenv |
no outgoing calls