Commit 53acb6e7 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Fix _putenv_s return value on error.

parent 8f6b8e97
......@@ -165,17 +165,22 @@ finish:
*/
errno_t CDECL _putenv_s(const char *name, const char *value)
{
int ret;
errno_t ret = 0;
TRACE("%s %s\n", debugstr_a(name), debugstr_a(value));
if (!MSVCRT_CHECK_PMT(name != NULL)) return -1;
if (!MSVCRT_CHECK_PMT(value != NULL)) return -1;
if (!MSVCRT_CHECK_PMT(name != NULL)) return EINVAL;
if (!MSVCRT_CHECK_PMT(value != NULL)) return EINVAL;
ret = SetEnvironmentVariableA(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 (!SetEnvironmentVariableA(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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment