Module: wine Branch: master Commit: f0e6447b7fc10c21bf6aa04f70a5094f16a294a5 URL: https://gitlab.winehq.org/wine/wine/-/commit/f0e6447b7fc10c21bf6aa04f70a5094...
Author: Piotr Caban piotr@codeweavers.com Date: Fri Oct 21 13:30:19 2022 +0200
msvcrt: Fix _wputenv_s return value on error.
---
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 a35d0877891..9800a1b66b1 100644 --- a/dlls/msvcrt/environ.c +++ b/dlls/msvcrt/environ.c @@ -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);