mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 08:08:43 +00:00
AK: Add Error::from_windows_error(void)
Also slightly improve Error::from_windows_error(int)
This commit is contained in:
parent
c7fe7b09a5
commit
870cce9d11
Notes:
github-actions[bot]
2025-02-06 02:28:57 +00:00
Author: https://github.com/stasoid
Commit: 870cce9d11
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3166
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/gmta
5 changed files with 40 additions and 34 deletions
|
@ -30,7 +30,7 @@ ErrorOr<NonnullRefPtr<AnonymousBufferImpl>> AnonymousBufferImpl::create(size_t s
|
|||
{
|
||||
HANDLE map_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, size >> 31 >> 1, size & 0xFFFFFFFF, NULL);
|
||||
if (!map_handle)
|
||||
return Error::from_windows_error(GetLastError());
|
||||
return Error::from_windows_error();
|
||||
|
||||
return create((int)(intptr_t)map_handle, size);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ ErrorOr<NonnullRefPtr<AnonymousBufferImpl>> AnonymousBufferImpl::create(int fd,
|
|||
{
|
||||
void* ptr = MapViewOfFile((HANDLE)(intptr_t)fd, FILE_MAP_ALL_ACCESS, 0, 0, size);
|
||||
if (!ptr)
|
||||
return Error::from_windows_error(GetLastError());
|
||||
return Error::from_windows_error();
|
||||
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousBufferImpl(fd, size, ptr));
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ ErrorOr<Process> Process::spawn(ProcessSpawnOptions const& options)
|
|||
&process_info);
|
||||
|
||||
if (!result)
|
||||
return Error::from_windows_error(GetLastError());
|
||||
return Error::from_windows_error();
|
||||
|
||||
CloseHandle(process_info.hThread);
|
||||
|
||||
|
@ -108,7 +108,7 @@ ErrorOr<String> Process::get_name()
|
|||
|
||||
DWORD length = GetModuleFileNameW(NULL, path, MAX_PATH);
|
||||
if (!length)
|
||||
return Error::from_windows_error(GetLastError());
|
||||
return Error::from_windows_error();
|
||||
|
||||
return String::from_utf16(Utf16View { { (u16*)path, length } });
|
||||
}
|
||||
|
@ -150,11 +150,11 @@ ErrorOr<int> Process::wait_for_termination()
|
|||
{
|
||||
auto result = WaitForSingleObject(m_handle, INFINITE);
|
||||
if (result == WAIT_FAILED)
|
||||
return Error::from_windows_error(GetLastError());
|
||||
return Error::from_windows_error();
|
||||
|
||||
DWORD exit_code = 0;
|
||||
if (!GetExitCodeProcess(m_handle, &exit_code))
|
||||
return Error::from_windows_error(GetLastError());
|
||||
return Error::from_windows_error();
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ ErrorOr<int> open(StringView path, int options, mode_t mode)
|
|||
if (::stat(sz_path, &st) == 0 && (st.st_mode & S_IFDIR)) {
|
||||
HANDLE dir_handle = CreateFile(sz_path, GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
if (dir_handle == INVALID_HANDLE_VALUE)
|
||||
return Error::from_windows_error(GetLastError());
|
||||
return Error::from_windows_error();
|
||||
int dir_fd = _open_osfhandle((intptr_t)dir_handle, 0);
|
||||
if (dir_fd != -1)
|
||||
return dir_fd;
|
||||
|
@ -84,7 +84,7 @@ ErrorOr<void> ftruncate(int fd, off_t length)
|
|||
return result.release_error();
|
||||
|
||||
if (SetEndOfFile((HANDLE)_get_osfhandle(fd)) == 0)
|
||||
return Error::from_windows_error(GetLastError());
|
||||
return Error::from_windows_error();
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue