ws2_32: getaddrinfo must SetLastError on success or failure.

This commit is contained in:
Bruno Jesus 2015-01-19 21:23:36 -02:00 committed by Alexandre Julliard
parent 512a814efc
commit 038399fcdd
2 changed files with 27 additions and 1 deletions

View File

@ -5628,7 +5628,11 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
const char *node;
*res = NULL;
if (!nodename && !servname) return WSAHOST_NOT_FOUND;
if (!nodename && !servname)
{
SetLastError(WSAHOST_NOT_FOUND);
return WSAHOST_NOT_FOUND;
}
if (!nodename)
node = NULL;
@ -5749,6 +5753,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
} else
result = convert_eai_u2w(result);
SetLastError(result);
return result;
outofmem:

View File

@ -5880,14 +5880,18 @@ static void test_GetAddrInfoW(void)
memset(&hint, 0, sizeof(ADDRINFOW));
result = (ADDRINFOW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoW(NULL, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoW(empty, NULL, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
pFreeAddrInfoW(result);
result = NULL;
@ -5906,6 +5910,7 @@ static void test_GetAddrInfoW(void)
result = NULL;
ret = pGetAddrInfoW(empty, zero, NULL, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
ok(result != NULL, "GetAddrInfoW failed\n");
result2 = NULL;
@ -5942,11 +5947,14 @@ static void test_GetAddrInfoW(void)
pFreeAddrInfoW(result);
result = NULL;
SetLastError(0xdeadbeef);
ret = pGetAddrInfoW(localhost, port, &hint, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
pFreeAddrInfoW(result);
result = (ADDRINFOW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoW(NULL, NULL, NULL, &result);
if(ret == 0)
{
@ -5954,9 +5962,11 @@ static void test_GetAddrInfoW(void)
return;
}
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = (ADDRINFOW *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = pGetAddrInfoW(nxdomain, NULL, NULL, &result);
if(ret == 0)
{
@ -5964,6 +5974,7 @@ static void test_GetAddrInfoW(void)
return;
}
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
for (i = 0;i < (sizeof(hinttests) / sizeof(hinttests[0]));i++)
@ -6031,14 +6042,18 @@ static void test_getaddrinfo(void)
memset(&hint, 0, sizeof(ADDRINFOA));
result = (ADDRINFOA *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = pgetaddrinfo(NULL, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = pgetaddrinfo("", NULL, NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(result != NULL, "getaddrinfo failed\n");
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
pfreeaddrinfo(result);
result = NULL;
@ -6055,8 +6070,10 @@ static void test_getaddrinfo(void)
pfreeaddrinfo(result2);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = pgetaddrinfo("", "0", NULL, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
ok(result != NULL, "getaddrinfo failed\n");
result2 = NULL;
@ -6093,11 +6110,14 @@ static void test_getaddrinfo(void)
pfreeaddrinfo(result);
result = NULL;
WSASetLastError(0xdeadbeef);
ret = pgetaddrinfo("localhost", "80", &hint, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
ok(WSAGetLastError() == 0, "expected 0, got %d\n", WSAGetLastError());
pfreeaddrinfo(result);
result = (ADDRINFOA *)0xdeadbeef;
WSASetLastError(0xdeadbeef);
ret = pgetaddrinfo("nxdomain.codeweavers.com", NULL, NULL, &result);
if(ret == 0)
{
@ -6105,6 +6125,7 @@ static void test_getaddrinfo(void)
return;
}
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(WSAGetLastError() == WSAHOST_NOT_FOUND, "expected 11001, got %d\n", WSAGetLastError());
ok(result == NULL, "got %p\n", result);
for (i = 0;i < (sizeof(hinttests) / sizeof(hinttests[0]));i++)