Commit 4c06599c authored by Vladimir Panteleev's avatar Vladimir Panteleev Committed by Alexandre Julliard

kernelbase: Don't return ERROR_INSUFFICIENT_BUFFER from GetEnvironmentVariableW.

Windows doesn't do this (except XP, and then only for empty variables, where it returns ERROR_MORE_DATA). Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48471Signed-off-by: 's avatarVladimir Panteleev <git@vladimir.panteleev.md> Signed-off-by: 's avatarGijs Vermeulen <gijsvrm@gmail.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 7ad5e1bc
......@@ -106,9 +106,12 @@ static void test_GetSetEnvironmentVariableA(void)
GetLastError());
/* Try to retrieve the environment variable we just set */
SetLastError(0xdeadbeef);
ret_size = GetEnvironmentVariableA(name, NULL, 0);
ok(ret_size == strlen(value) + 1,
"should return length with terminating 0 ret_size=%d\n", ret_size);
ok(GetLastError() == 0xdeadbeef,
"should not fail with zero size but GetLastError=%d\n", GetLastError());
lstrcpyA(buf, "foo");
ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value));
......@@ -208,10 +211,13 @@ static void test_GetSetEnvironmentVariableW(void)
GetLastError());
/* Try to retrieve the environment variable we just set */
SetLastError(0xdeadbeef);
ret_size = GetEnvironmentVariableW(name, NULL, 0);
ok(ret_size == lstrlenW(value) + 1,
"should return length with terminating 0 ret_size=%d\n",
ret_size);
ok(GetLastError() == 0xdeadbeef,
"should not fail with zero size but GetLastError=%d\n", GetLastError());
lstrcpyW(buf, fooW);
ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value));
......
......@@ -1395,7 +1395,8 @@ DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableW( LPCWSTR name, LPWSTR val
status = RtlQueryEnvironmentVariable_U( NULL, &us_name, &us_value );
len = us_value.Length / sizeof(WCHAR);
if (!set_ntstatus( status )) return (status == STATUS_BUFFER_TOO_SMALL) ? len + 1 : 0;
if (status == STATUS_BUFFER_TOO_SMALL) return len + 1;
if (!set_ntstatus( status )) return 0;
if (size) val[len] = 0;
return len;
}
......
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