mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-26 20:26:53 +00:00
LibCore: Add Windows version of DirIterator
Co-authored-by: stasoid <stasoid@yahoo.com>
This commit is contained in:
parent
c5219b0193
commit
94601e1ffd
Notes:
github-actions[bot]
2024-10-20 00:15:43 +00:00
Author: https://github.com/stasoid
Commit: 94601e1ffd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1832
Reviewed-by: https://github.com/ADKaster ✅
8 changed files with 238 additions and 21 deletions
36
AK/Error.cpp
36
AK/Error.cpp
|
@ -1,10 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
|
||||
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
|
||||
* Copyright (c) 2024, stasoid <stasoid@yahoo.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Error.h>
|
||||
#ifdef AK_OS_WINDOWS
|
||||
# include <AK/ByteString.h>
|
||||
# include <AK/HashMap.h>
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -13,4 +20,33 @@ Error Error::from_string_view_or_print_error_and_return_errno(StringView string_
|
|||
return Error::from_string_view(string_literal);
|
||||
}
|
||||
|
||||
#ifdef AK_OS_WINDOWS
|
||||
Error Error::from_windows_error(DWORD code)
|
||||
{
|
||||
static HashMap<DWORD, ByteString> windows_errors;
|
||||
|
||||
auto string = windows_errors.get(code);
|
||||
if (string.has_value()) {
|
||||
return Error::from_string_view(string->view());
|
||||
} else {
|
||||
char* message = nullptr;
|
||||
auto size = FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr,
|
||||
code,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)&message,
|
||||
0,
|
||||
nullptr);
|
||||
|
||||
if (size == 0)
|
||||
return Error::from_string_view_or_print_error_and_return_errno("Unknown error"sv, code);
|
||||
|
||||
windows_errors.set(code, { message, size });
|
||||
LocalFree(message);
|
||||
return from_windows_error(code);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue