| 179 | return status; |
| 180 | } |
| 181 | static inline int cbm_unsetenv(const char *name) { |
| 182 | if (!name) { |
| 183 | return EINVAL; |
| 184 | } |
| 185 | int name_chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, name, -1, NULL, 0); |
| 186 | wchar_t *wide_name = |
| 187 | name_chars > 0 ? (wchar_t *)malloc((size_t)name_chars * sizeof(*wide_name)) : NULL; |
| 188 | if (!wide_name || |
| 189 | MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, name, -1, wide_name, name_chars) <= 0) { |
| 190 | free(wide_name); |
| 191 | return EINVAL; |
| 192 | } |
| 193 | int status = _putenv_s(name, ""); |
| 194 | if (status == 0) { |
| 195 | SetLastError(ERROR_SUCCESS); |
| 196 | if (!SetEnvironmentVariableW(wide_name, NULL) && GetLastError() != ERROR_ENVVAR_NOT_FOUND) { |
| 197 | status = EINVAL; |
| 198 | } |
| 199 | } |
| 200 | free(wide_name); |
| 201 | return status; |
| 202 | } |
| 203 | #else |
| 204 | #define cbm_setenv setenv |
| 205 | #define cbm_unsetenv unsetenv |
no outgoing calls