Bruno Jesus : ws2_32: Implement WSAEnumProtocols[A|W] using a helper function.
Alexandre Julliard
julliard at winehq.org
Fri Aug 16 14:23:46 CDT 2013
Module: wine
Branch: master
Commit: 5fa343047f187d9a3733d460277be541f70f53de
URL: http://source.winehq.org/git/wine.git/?a=commit;h=5fa343047f187d9a3733d460277be541f70f53de
Author: Bruno Jesus <00cpxxx at gmail.com>
Date: Wed Aug 7 00:18:17 2013 -0300
ws2_32: Implement WSAEnumProtocols[A|W] using a helper function.
---
dlls/ws2_32/protocol.c | 61 ++++++++++++++++++++++-------------------------
1 files changed, 29 insertions(+), 32 deletions(-)
diff --git a/dlls/ws2_32/protocol.c b/dlls/ws2_32/protocol.c
index 98e7c38..c039e7c 100644
--- a/dlls/ws2_32/protocol.c
+++ b/dlls/ws2_32/protocol.c
@@ -204,22 +204,23 @@ static INT WINSOCK_EnterSingleProtocolA( INT protocol, WSAPROTOCOL_INFOA* info )
return ret;
}
-/*****************************************************************************
- * WSAEnumProtocolsA [WS2_32.@]
- *
- * see function WSAEnumProtocolsW
- */
-INT WINAPI WSAEnumProtocolsA( LPINT protocols, LPWSAPROTOCOL_INFOA buffer, LPDWORD len )
+static INT WINSOCK_EnumProtocols( BOOL unicode, LPINT protocols, LPWSAPROTOCOL_INFOW buffer, LPDWORD len )
{
INT i = 0;
DWORD size = 0;
INT local[] = { WS_IPPROTO_TCP, WS_IPPROTO_UDP, NSPROTO_IPX, NSPROTO_SPX, NSPROTO_SPXII, 0 };
+ union _info
+ {
+ LPWSAPROTOCOL_INFOA a;
+ LPWSAPROTOCOL_INFOW w;
+ } info;
+ info.w = buffer;
if (!protocols) protocols = local;
while (protocols[i]) i++;
- size = i * sizeof(WSAPROTOCOL_INFOA);
+ size = i * (unicode ? sizeof(WSAPROTOCOL_INFOW) : sizeof(WSAPROTOCOL_INFOA));
if (*len < size || !buffer)
{
@@ -230,13 +231,31 @@ INT WINAPI WSAEnumProtocolsA( LPINT protocols, LPWSAPROTOCOL_INFOA buffer, LPDWO
for (i = 0; protocols[i]; i++)
{
- if (WINSOCK_EnterSingleProtocolA( protocols[i], &buffer[i] ) == SOCKET_ERROR)
- return i;
+ if (unicode)
+ {
+ if (WINSOCK_EnterSingleProtocolW( protocols[i], &info.w[i] ) == SOCKET_ERROR)
+ break;
+ }
+ else
+ {
+ if (WINSOCK_EnterSingleProtocolA( protocols[i], &info.a[i] ) == SOCKET_ERROR)
+ break;
+ }
}
return i;
}
/*****************************************************************************
+ * WSAEnumProtocolsA [WS2_32.@]
+ *
+ * see function WSAEnumProtocolsW
+ */
+INT WINAPI WSAEnumProtocolsA( LPINT protocols, LPWSAPROTOCOL_INFOA buffer, LPDWORD len )
+{
+ return WINSOCK_EnumProtocols( FALSE, protocols, (LPWSAPROTOCOL_INFOW) buffer, len);
+}
+
+/*****************************************************************************
* WSAEnumProtocolsW [WS2_32.@]
*
* Retrieves information about specified set of active network protocols.
@@ -275,29 +294,7 @@ INT WINAPI WSAEnumProtocolsA( LPINT protocols, LPWSAPROTOCOL_INFOA buffer, LPDWO
*/
INT WINAPI WSAEnumProtocolsW( LPINT protocols, LPWSAPROTOCOL_INFOW buffer, LPDWORD len )
{
- INT i = 0;
- DWORD size = 0;
- INT local[] = { WS_IPPROTO_TCP, WS_IPPROTO_UDP, NSPROTO_IPX, NSPROTO_SPX, NSPROTO_SPXII, 0 };
-
- if (!protocols) protocols = local;
-
- while (protocols[i]) i++;
-
- size = i * sizeof(WSAPROTOCOL_INFOW);
-
- if (*len < size || !buffer)
- {
- *len = size;
- WSASetLastError(WSAENOBUFS);
- return SOCKET_ERROR;
- }
-
- for (i = 0; protocols[i]; i++)
- {
- if (WINSOCK_EnterSingleProtocolW( protocols[i], &buffer[i] ) == SOCKET_ERROR)
- return i;
- }
- return i;
+ return WINSOCK_EnumProtocols( TRUE, protocols, buffer, len);
}
/*****************************************************************************
More information about the wine-cvs
mailing list