AK: Simplify usage of windows.h and winsock2.h

Use <AK/Windows.h> instead of windows.h/winsock2.h
to avoid timeval-related errors.

Note: winsock2.h includes windows.h
This commit is contained in:
stasoid 2024-12-01 14:43:10 +05:00 committed by Andrew Kaster
parent 3eefa464ee
commit 49bdda1475
Notes: github-actions[bot] 2025-01-02 17:18:48 +00:00
4 changed files with 24 additions and 9 deletions

View file

@ -8,9 +8,7 @@
#include <AK/Time.h>
#ifdef AK_OS_WINDOWS
# define timeval dummy_timeval
# include <windows.h>
# undef timeval
# include <AK/Windows.h>
#endif
namespace AK {

21
AK/Windows.h Normal file
View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 2024, stasoid <stasoid@yahoo.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
// This header should be included only in cpp files.
// It should be included after all other files and should be separated from them by a non-#include line to prevent clang-format from changing header order.
#pragma once
#include <AK/Platform.h>
#ifdef AK_OS_WINDOWS // needed for Swift
# define timeval dummy_timeval
# include <winsock2.h>
# undef timeval
# undef IN
# pragma comment(lib, "ws2_32.lib")
# include <io.h>
#endif

View file

@ -110,7 +110,3 @@ endif()
if (ANDROID)
target_link_libraries(LibCore PRIVATE log)
endif()
if (WIN32)
target_link_libraries(LibCore PRIVATE ws2_32.lib)
endif()

View file

@ -8,8 +8,8 @@
#include <LibCore/EventLoopImplementationWindows.h>
#include <LibCore/Notifier.h>
#include <LibCore/ThreadEventQueue.h>
#include <WinSock2.h>
#include <io.h>
#include <AK/Windows.h>
struct Handle {
HANDLE handle = NULL;