mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 05:27:14 +09:00
AK+LibCore: Avoid double-negation of syscall error values
This is a remnant from SerenityOS. Let's avoid confusion as to why we negate errno when we call Error::from_syscall just to negate it again when we store the error code.
This commit is contained in:
parent
24ac5e2eee
commit
dceed08058
Notes:
github-actions[bot]
2025-05-11 01:21:05 +00:00
Author: https://github.com/trflynn89
Commit: dceed08058
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4689
7 changed files with 100 additions and 100 deletions
|
@ -45,7 +45,7 @@ ErrorOr<int> open(StringView path, int options, mode_t mode)
|
|||
ByteString str = path;
|
||||
int fd = _open(str.characters(), options | O_BINARY | _O_OBTAIN_DIR, mode);
|
||||
if (fd < 0)
|
||||
return Error::from_syscall("open"sv, -errno);
|
||||
return Error::from_syscall("open"sv, errno);
|
||||
ScopeGuard guard = [&] { _close(fd); };
|
||||
return dup(_get_osfhandle(fd));
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ ErrorOr<struct stat> fstat(int handle)
|
|||
int fd = _open_osfhandle(TRY(dup(handle)), 0);
|
||||
ScopeGuard guard = [&] { _close(fd); };
|
||||
if (::fstat(fd, &st) < 0)
|
||||
return Error::from_syscall("fstat"sv, -errno);
|
||||
return Error::from_syscall("fstat"sv, errno);
|
||||
return st;
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ ErrorOr<ByteString> getcwd()
|
|||
{
|
||||
auto* cwd = _getcwd(nullptr, 0);
|
||||
if (!cwd)
|
||||
return Error::from_syscall("getcwd"sv, -errno);
|
||||
return Error::from_syscall("getcwd"sv, errno);
|
||||
|
||||
ByteString string_cwd(cwd);
|
||||
free(cwd);
|
||||
|
@ -129,12 +129,12 @@ ErrorOr<ByteString> getcwd()
|
|||
ErrorOr<struct stat> stat(StringView path)
|
||||
{
|
||||
if (path.is_null())
|
||||
return Error::from_syscall("stat"sv, -EFAULT);
|
||||
return Error::from_syscall("stat"sv, EFAULT);
|
||||
|
||||
struct stat st = {};
|
||||
ByteString path_string = path;
|
||||
if (::stat(path_string.characters(), &st) < 0)
|
||||
return Error::from_syscall("stat"sv, -errno);
|
||||
return Error::from_syscall("stat"sv, errno);
|
||||
return st;
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ ErrorOr<void> rmdir(StringView path)
|
|||
|
||||
ByteString path_string = path;
|
||||
if (_rmdir(path_string.characters()) < 0)
|
||||
return Error::from_syscall("rmdir"sv, -errno);
|
||||
return Error::from_syscall("rmdir"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ ErrorOr<void> unlink(StringView path)
|
|||
|
||||
ByteString path_string = path;
|
||||
if (_unlink(path_string.characters()) < 0)
|
||||
return Error::from_syscall("unlink"sv, -errno);
|
||||
return Error::from_syscall("unlink"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ ErrorOr<void> mkdir(StringView path, mode_t)
|
|||
{
|
||||
ByteString str = path;
|
||||
if (_mkdir(str.characters()) < 0)
|
||||
return Error::from_syscall("mkdir"sv, -errno);
|
||||
return Error::from_syscall("mkdir"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -188,14 +188,14 @@ ErrorOr<void*> mmap(void* address, size_t size, int protection, int flags, int f
|
|||
ScopeGuard guard = [&] { _close(fd); };
|
||||
void* ptr = ::mmap(address, size, protection, flags, fd, offset);
|
||||
if (ptr == MAP_FAILED)
|
||||
return Error::from_syscall("mmap"sv, -errno);
|
||||
return Error::from_syscall("mmap"sv, errno);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ErrorOr<void> munmap(void* address, size_t size)
|
||||
{
|
||||
if (::munmap(address, size) < 0)
|
||||
return Error::from_syscall("munmap"sv, -errno);
|
||||
return Error::from_syscall("munmap"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue