Skip to content

Commit

Permalink
replace __WINDOWS__ checks with standart _WIN32
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Jan 24, 2024
1 parent 437d757 commit b2ca02c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/SDL_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
3. This notice may not be removed or altered from any source distribution.
*/

#ifdef _WIN32
#ifdef _WIN32_WINNT
# if _WIN32_WINNT < 0x0600 // we need APIs that didn't arrive until Windows Vista.
# undef _WIN32_WINNT
Expand All @@ -27,10 +28,11 @@
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0600
#endif
#endif /* _WIN32 */

#include "SDL3_net/SDL_net.h"

#ifdef __WINDOWS__
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <winsock2.h>
#include <ws2tcpip.h>
Expand Down Expand Up @@ -133,7 +135,7 @@ static int RandomNumberBetween(const int lo, const int hi)

static int CloseSocketHandle(Socket handle)
{
#ifdef __WINDOWS__
#ifdef _WIN32
return closesocket(handle);
#else
return close(handle);
Expand All @@ -142,7 +144,7 @@ static int CloseSocketHandle(Socket handle)

static int LastSocketError(void)
{
#ifdef __WINDOWS__
#ifdef _WIN32
return WSAGetLastError();
#else
return errno;
Expand All @@ -151,7 +153,7 @@ static int LastSocketError(void)

static char *CreateSocketErrorString(int rc)
{
#ifdef __WINDOWS__
#ifdef _WIN32
WCHAR msgbuf[256];
const DWORD bw = FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM |
Expand All @@ -174,7 +176,7 @@ static char *CreateSocketErrorString(int rc)

static char *CreateGetAddrInfoErrorString(int rc)
{
#ifdef __WINDOWS__
#ifdef _WIN32
return CreateSocketErrorString(rc); // same error codes.
#else
return SDL_strdup((rc == EAI_SYSTEM) ? strerror(errno) : gai_strerror(rc));
Expand Down Expand Up @@ -371,7 +373,7 @@ int SDLNet_Init(void)

char *origerrstr = NULL;

#ifdef __WINDOWS__
#ifdef _WIN32
WSADATA data;
if (WSAStartup(MAKEWORD(1, 1), &data) != 0) {
return SetSocketError("WSAStartup() failed", LastSocketError());
Expand Down Expand Up @@ -462,7 +464,7 @@ void SDLNet_Quit(void)

resolver_queue = NULL;

#ifdef __WINDOWS__
#ifdef _WIN32
WSACleanup();
#endif
}
Expand Down Expand Up @@ -637,7 +639,7 @@ SDLNet_Address **SDLNet_GetLocalAddresses(int *num_addresses)

*num_addresses = 0;

#ifdef __WINDOWS__
#ifdef _WIN32
// !!! FIXME: maybe LoadLibrary(iphlpapi) on the first call, since most
// !!! FIXME: things won't ever use this.

Expand Down Expand Up @@ -802,7 +804,7 @@ struct SDLNet_StreamSocket

static int MakeSocketNonblocking(Socket handle)
{
#ifdef __WINDOWS__
#ifdef _WIN32
DWORD one = 1;
return ioctlsocket(handle, FIONBIO, &one);
#else
Expand All @@ -812,7 +814,7 @@ static int MakeSocketNonblocking(Socket handle)

static SDL_bool WouldBlock(const int err)
{
#ifdef __WINDOWS__
#ifdef _WIN32
return (err == WSAEWOULDBLOCK) ? SDL_TRUE : SDL_FALSE;
#else
return ((err == EWOULDBLOCK) || (err == EAGAIN) || (err == EINPROGRESS)) ? SDL_TRUE : SDL_FALSE;
Expand Down

0 comments on commit b2ca02c

Please sign in to comment.