msvcrt: Fix _wputenv_s return value on error.
This commit is contained in:
parent
53acb6e736
commit
f0e6447b7f
1 changed files with 11 additions and 6 deletions
|
@ -191,19 +191,24 @@ errno_t CDECL _putenv_s(const char *name, const char *value)
|
|||
/*********************************************************************
|
||||
* _wputenv_s (MSVCRT.@)
|
||||
*/
|
||||
int CDECL _wputenv_s(const wchar_t *name, const wchar_t *value)
|
||||
errno_t CDECL _wputenv_s(const wchar_t *name, const wchar_t *value)
|
||||
{
|
||||
int ret;
|
||||
errno_t ret = 0;
|
||||
|
||||
TRACE("%s %s\n", debugstr_w(name), debugstr_w(value));
|
||||
|
||||
if (!MSVCRT_CHECK_PMT(name != NULL)) return -1;
|
||||
if (!MSVCRT_CHECK_PMT(value != NULL)) return -1;
|
||||
|
||||
ret = SetEnvironmentVariableW(name, value[0] ? value : NULL) ? 0 : -1;
|
||||
|
||||
/* _putenv returns success on deletion of nonexistent variable, unlike [Rtl]SetEnvironmentVariable */
|
||||
if ((ret == -1) && (GetLastError() == ERROR_ENVVAR_NOT_FOUND)) ret = 0;
|
||||
if (!SetEnvironmentVariableW(name, value[0] ? value : NULL))
|
||||
{
|
||||
/* _putenv returns success on deletion of nonexistent variable */
|
||||
if (GetLastError() != ERROR_ENVVAR_NOT_FOUND)
|
||||
{
|
||||
msvcrt_set_errno(GetLastError());
|
||||
ret = *_errno();
|
||||
}
|
||||
}
|
||||
|
||||
MSVCRT__environ = msvcrt_SnapshotOfEnvironmentA(MSVCRT__environ);
|
||||
MSVCRT__wenviron = msvcrt_SnapshotOfEnvironmentW(MSVCRT__wenviron);
|
||||
|
|
Loading…
Add table
Reference in a new issue