Piotr Caban : msvcrt: Fix _wputenv_s return value on error.
Module: wine Branch: oldstable Commit: d4a998f795bd354284abc451f256facbdf192228 URL: https://gitlab.winehq.org/wine/wine/-/commit/d4a998f795bd354284abc451f256fac... Author: Piotr Caban <piotr(a)codeweavers.com> Date: Fri Oct 21 13:30:19 2022 +0200 msvcrt: Fix _wputenv_s return value on error. (cherry picked from commit f0e6447b7fc10c21bf6aa04f70a5094f16a294a5) Signed-off-by: Michael Stefaniuc <mstefani(a)winehq.org> --- dlls/msvcrt/environ.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/dlls/msvcrt/environ.c b/dlls/msvcrt/environ.c index 698dc761381..5e07fe5e367 100644 --- a/dlls/msvcrt/environ.c +++ b/dlls/msvcrt/environ.c @@ -186,19 +186,24 @@ int 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);
participants (1)
-
Alexandre Julliard