From a47848f304965fe4baf548697ae79ed8db73e8b3 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 27 Jul 2022 14:53:15 +0200 Subject: [PATCH] Detect Windows using _WIN32 in network util For consistency, always use _WIN32 instead of a mix of __WINDOWS__ and _WIN32. --- app/src/util/net.c | 15 +++++++-------- app/src/util/net.h | 5 ++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/src/util/net.c b/app/src/util/net.c index b1aa7445..e5f84676 100644 --- a/app/src/util/net.c +++ b/app/src/util/net.c @@ -3,11 +3,10 @@ #include #include #include -#include #include "log.h" -#ifdef __WINDOWS__ +#ifdef _WIN32 # include typedef int socklen_t; typedef SOCKET sc_raw_socket; @@ -29,7 +28,7 @@ bool net_init(void) { -#ifdef __WINDOWS__ +#ifdef _WIN32 WSADATA wsa; int res = WSAStartup(MAKEWORD(2, 2), &wsa) < 0; if (res < 0) { @@ -42,14 +41,14 @@ net_init(void) { void net_cleanup(void) { -#ifdef __WINDOWS__ +#ifdef _WIN32 WSACleanup(); #endif } static inline sc_socket wrap(sc_raw_socket sock) { -#ifdef __WINDOWS__ +#ifdef _WIN32 if (sock == INVALID_SOCKET) { return SC_SOCKET_NONE; } @@ -72,7 +71,7 @@ wrap(sc_raw_socket sock) { static inline sc_raw_socket unwrap(sc_socket socket) { -#ifdef __WINDOWS__ +#ifdef _WIN32 if (socket == SC_SOCKET_NONE) { return INVALID_SOCKET; } @@ -248,7 +247,7 @@ net_interrupt(sc_socket socket) { sc_raw_socket raw_sock = unwrap(socket); -#ifdef __WINDOWS__ +#ifdef _WIN32 if (!atomic_flag_test_and_set(&socket->closed)) { return !closesocket(raw_sock); } @@ -262,7 +261,7 @@ bool net_close(sc_socket socket) { sc_raw_socket raw_sock = unwrap(socket); -#ifdef __WINDOWS__ +#ifdef _WIN32 bool ret = true; if (!atomic_flag_test_and_set(&socket->closed)) { ret = !closesocket(raw_sock); diff --git a/app/src/util/net.h b/app/src/util/net.h index d9289981..801bdeaf 100644 --- a/app/src/util/net.h +++ b/app/src/util/net.h @@ -5,9 +5,8 @@ #include #include -#include -#ifdef __WINDOWS__ +#ifdef _WIN32 # include # include @@ -17,7 +16,7 @@ atomic_flag closed; } *sc_socket; -#else // not __WINDOWS__ +#else // not _WIN32 # include # define SC_SOCKET_NONE -1