mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-07 21:17:07 +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
|
@ -36,9 +36,9 @@ public:
|
|||
static Error from_windows_error();
|
||||
#endif
|
||||
|
||||
static Error from_syscall(StringView syscall_name, int rc)
|
||||
static Error from_syscall(StringView syscall_name, int code)
|
||||
{
|
||||
return Error(syscall_name, rc);
|
||||
return Error(syscall_name, code);
|
||||
}
|
||||
static Error from_string_view(StringView string_literal) { return Error(string_literal); }
|
||||
|
||||
|
@ -113,9 +113,9 @@ private:
|
|||
{
|
||||
}
|
||||
|
||||
Error(StringView syscall_name, int rc)
|
||||
Error(StringView syscall_name, int code)
|
||||
: m_string_literal(syscall_name)
|
||||
, m_code(-rc)
|
||||
, m_code(code)
|
||||
, m_kind(Kind::Syscall)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ Directory::~Directory()
|
|||
ErrorOr<void> Directory::chown(uid_t uid, gid_t gid)
|
||||
{
|
||||
if (m_directory_fd == -1)
|
||||
return Error::from_syscall("fchown"sv, -EBADF);
|
||||
return Error::from_syscall("fchown"sv, EBADF);
|
||||
TRY(Core::System::fchown(m_directory_fd, uid, gid));
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ ErrorOr<NonnullOwnPtr<LocalSocket>> LocalServer::accept()
|
|||
int accepted_fd = ::accept(m_fd, (sockaddr*)&un, &un_size);
|
||||
#endif
|
||||
if (accepted_fd < 0) {
|
||||
return Error::from_syscall("accept"sv, -errno);
|
||||
return Error::from_syscall("accept"sv, errno);
|
||||
}
|
||||
|
||||
#if defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_HAIKU)
|
||||
|
|
|
@ -182,7 +182,7 @@ ErrorOr<String> Process::get_name()
|
|||
char buffer[BUFSIZ];
|
||||
int rc = get_process_name(buffer, BUFSIZ);
|
||||
if (rc != 0)
|
||||
return Error::from_syscall("get_process_name"sv, -rc);
|
||||
return Error::from_syscall("get_process_name"sv, rc);
|
||||
return String::from_utf8(StringView { buffer, strlen(buffer) });
|
||||
#elif defined(AK_LIBC_GLIBC) || (defined(AK_OS_LINUX) && !defined(AK_OS_ANDROID))
|
||||
return String::from_utf8(StringView { program_invocation_name, strlen(program_invocation_name) });
|
||||
|
@ -200,13 +200,13 @@ ErrorOr<void> Process::set_name([[maybe_unused]] StringView name, [[maybe_unused
|
|||
#if defined(AK_OS_SERENITY)
|
||||
int rc = set_process_name(name.characters_without_null_termination(), name.length());
|
||||
if (rc != 0)
|
||||
return Error::from_syscall("set_process_name"sv, -rc);
|
||||
return Error::from_syscall("set_process_name"sv, rc);
|
||||
if (set_thread_name == SetThreadName::No)
|
||||
return {};
|
||||
|
||||
rc = prctl(PR_SET_THREAD_NAME, gettid(), name.characters_without_null_termination(), name.length());
|
||||
if (rc != 0)
|
||||
return Error::from_syscall("set_thread_name"sv, -rc);
|
||||
return Error::from_syscall("set_thread_name"sv, rc);
|
||||
return {};
|
||||
#else
|
||||
// FIXME: Implement Process::set_name() for other platforms.
|
||||
|
@ -232,7 +232,7 @@ ErrorOr<bool> Process::is_being_debugged()
|
|||
#elif defined(AK_OS_GNU_HURD)
|
||||
process_t proc = getproc();
|
||||
if (!MACH_PORT_VALID(proc))
|
||||
return Error::from_syscall("getproc"sv, -errno);
|
||||
return Error::from_syscall("getproc"sv, errno);
|
||||
|
||||
int flags = PI_FETCH_TASKINFO;
|
||||
// We're going to ask the proc server for the info about our process,
|
||||
|
@ -253,7 +253,7 @@ ErrorOr<bool> Process::is_being_debugged()
|
|||
mach_port_deallocate(mach_task_self(), proc);
|
||||
if (err) {
|
||||
__hurd_fail(static_cast<error_t>(err));
|
||||
return Error::from_syscall("proc_getprocinfo"sv, -errno);
|
||||
return Error::from_syscall("proc_getprocinfo"sv, errno);
|
||||
}
|
||||
|
||||
// Now cast the returned buffer pointer back to struct procinfo, and
|
||||
|
@ -284,7 +284,7 @@ ErrorOr<bool> Process::is_being_debugged()
|
|||
mib[3] = getpid();
|
||||
|
||||
if (sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0) < 0)
|
||||
return Error::from_syscall("sysctl"sv, -errno);
|
||||
return Error::from_syscall("sysctl"sv, errno);
|
||||
|
||||
// We're being debugged if the P_TRACED flag is set.
|
||||
# if defined(AK_OS_MACOS)
|
||||
|
@ -346,7 +346,7 @@ ErrorOr<int> Process::wait_for_termination()
|
|||
int exit_code = -1;
|
||||
int status;
|
||||
if (waitpid(m_pid, &status, 0) == -1)
|
||||
return Error::from_syscall("waitpid"sv, -errno);
|
||||
return Error::from_syscall("waitpid"sv, errno);
|
||||
|
||||
if (WIFEXITED(status)) {
|
||||
exit_code = WEXITSTATUS(status);
|
||||
|
|
|
@ -65,7 +65,7 @@ ErrorOr<int> accept4(int sockfd, sockaddr* address, socklen_t* address_length, i
|
|||
{
|
||||
auto fd = ::accept4(sockfd, address, address_length, flags);
|
||||
if (fd < 0)
|
||||
return Error::from_syscall("accept4"sv, -errno);
|
||||
return Error::from_syscall("accept4"sv, errno);
|
||||
return fd;
|
||||
}
|
||||
#endif
|
||||
|
@ -73,7 +73,7 @@ ErrorOr<int> accept4(int sockfd, sockaddr* address, socklen_t* address_length, i
|
|||
ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action)
|
||||
{
|
||||
if (::sigaction(signal, action, old_action) < 0)
|
||||
return Error::from_syscall("sigaction"sv, -errno);
|
||||
return Error::from_syscall("sigaction"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ ErrorOr<sighandler_t> signal(int signal, sighandler_t handler)
|
|||
{
|
||||
auto old_handler = ::signal(signal, handler);
|
||||
if (old_handler == SIG_ERR)
|
||||
return Error::from_syscall("signal"sv, -errno);
|
||||
return Error::from_syscall("signal"sv, errno);
|
||||
return old_handler;
|
||||
}
|
||||
|
||||
|
@ -95,14 +95,14 @@ ErrorOr<struct stat> fstat(int fd)
|
|||
{
|
||||
struct stat st = {};
|
||||
if (::fstat(fd, &st) < 0)
|
||||
return Error::from_syscall("fstat"sv, -errno);
|
||||
return Error::from_syscall("fstat"sv, errno);
|
||||
return st;
|
||||
}
|
||||
|
||||
ErrorOr<struct stat> fstatat(int fd, StringView path, int flags)
|
||||
{
|
||||
if (!path.characters_without_null_termination())
|
||||
return Error::from_syscall("fstatat"sv, -EFAULT);
|
||||
return Error::from_syscall("fstatat"sv, EFAULT);
|
||||
|
||||
struct stat st = {};
|
||||
ByteString path_string = path;
|
||||
|
@ -120,7 +120,7 @@ ErrorOr<int> fcntl(int fd, int command, ...)
|
|||
int rc = ::fcntl(fd, command, extra_arg);
|
||||
va_end(ap);
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("fcntl"sv, -errno);
|
||||
return Error::from_syscall("fcntl"sv, errno);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -130,14 +130,14 @@ ErrorOr<void*> mmap(void* address, size_t size, int protection, int flags, int f
|
|||
VERIFY(!alignment);
|
||||
auto* 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 {};
|
||||
}
|
||||
|
||||
|
@ -205,53 +205,53 @@ ErrorOr<int> open(StringView path, int options, mode_t mode)
|
|||
ErrorOr<int> openat(int fd, StringView path, int options, mode_t mode)
|
||||
{
|
||||
if (!path.characters_without_null_termination())
|
||||
return Error::from_syscall("open"sv, -EFAULT);
|
||||
return Error::from_syscall("open"sv, EFAULT);
|
||||
|
||||
// NOTE: We have to ensure that the path is null-terminated.
|
||||
ByteString path_string = path;
|
||||
int rc = ::openat(fd, path_string.characters(), options, mode);
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("open"sv, -errno);
|
||||
return Error::from_syscall("open"sv, errno);
|
||||
return rc;
|
||||
}
|
||||
|
||||
ErrorOr<void> close(int fd)
|
||||
{
|
||||
if (::close(fd) < 0)
|
||||
return Error::from_syscall("close"sv, -errno);
|
||||
return Error::from_syscall("close"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> ftruncate(int fd, off_t length)
|
||||
{
|
||||
if (::ftruncate(fd, length) < 0)
|
||||
return Error::from_syscall("ftruncate"sv, -errno);
|
||||
return Error::from_syscall("ftruncate"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<struct stat> stat(StringView path)
|
||||
{
|
||||
if (!path.characters_without_null_termination())
|
||||
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;
|
||||
}
|
||||
|
||||
ErrorOr<struct stat> lstat(StringView path)
|
||||
{
|
||||
if (!path.characters_without_null_termination())
|
||||
return Error::from_syscall("lstat"sv, -EFAULT);
|
||||
return Error::from_syscall("lstat"sv, EFAULT);
|
||||
|
||||
struct stat st = {};
|
||||
|
||||
ByteString path_string = path;
|
||||
if (::lstat(path_string.characters(), &st) < 0)
|
||||
return Error::from_syscall("lstat"sv, -errno);
|
||||
return Error::from_syscall("lstat"sv, errno);
|
||||
return st;
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ ErrorOr<ssize_t> read(int fd, Bytes buffer)
|
|||
{
|
||||
ssize_t rc = ::read(fd, buffer.data(), buffer.size());
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("read"sv, -errno);
|
||||
return Error::from_syscall("read"sv, errno);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -267,14 +267,14 @@ ErrorOr<ssize_t> write(int fd, ReadonlyBytes buffer)
|
|||
{
|
||||
ssize_t rc = ::write(fd, buffer.data(), buffer.size());
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("write"sv, -errno);
|
||||
return Error::from_syscall("write"sv, errno);
|
||||
return rc;
|
||||
}
|
||||
|
||||
ErrorOr<void> kill(pid_t pid, int signal)
|
||||
{
|
||||
if (::kill(pid, signal) < 0)
|
||||
return Error::from_syscall("kill"sv, -errno);
|
||||
return Error::from_syscall("kill"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ ErrorOr<int> dup(int source_fd)
|
|||
{
|
||||
int fd = ::dup(source_fd);
|
||||
if (fd < 0)
|
||||
return Error::from_syscall("dup"sv, -errno);
|
||||
return Error::from_syscall("dup"sv, errno);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ ErrorOr<int> dup2(int source_fd, int destination_fd)
|
|||
{
|
||||
int fd = ::dup2(source_fd, destination_fd);
|
||||
if (fd < 0)
|
||||
return Error::from_syscall("dup2"sv, -errno);
|
||||
return Error::from_syscall("dup2"sv, errno);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -298,7 +298,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);
|
||||
|
@ -316,7 +316,7 @@ ErrorOr<void> ioctl(int fd, unsigned request, ...)
|
|||
#endif
|
||||
va_end(ap);
|
||||
if (::ioctl(fd, request, arg) < 0)
|
||||
return Error::from_syscall("ioctl"sv, -errno);
|
||||
return Error::from_syscall("ioctl"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -324,50 +324,50 @@ ErrorOr<struct termios> tcgetattr(int fd)
|
|||
{
|
||||
struct termios ios = {};
|
||||
if (::tcgetattr(fd, &ios) < 0)
|
||||
return Error::from_syscall("tcgetattr"sv, -errno);
|
||||
return Error::from_syscall("tcgetattr"sv, errno);
|
||||
return ios;
|
||||
}
|
||||
|
||||
ErrorOr<void> tcsetattr(int fd, int optional_actions, struct termios const& ios)
|
||||
{
|
||||
if (::tcsetattr(fd, optional_actions, &ios) < 0)
|
||||
return Error::from_syscall("tcsetattr"sv, -errno);
|
||||
return Error::from_syscall("tcsetattr"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> chmod(StringView pathname, mode_t mode)
|
||||
{
|
||||
if (!pathname.characters_without_null_termination())
|
||||
return Error::from_syscall("chmod"sv, -EFAULT);
|
||||
return Error::from_syscall("chmod"sv, EFAULT);
|
||||
|
||||
ByteString path = pathname;
|
||||
if (::chmod(path.characters(), mode) < 0)
|
||||
return Error::from_syscall("chmod"sv, -errno);
|
||||
return Error::from_syscall("chmod"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> fchmod(int fd, mode_t mode)
|
||||
{
|
||||
if (::fchmod(fd, mode) < 0)
|
||||
return Error::from_syscall("fchmod"sv, -errno);
|
||||
return Error::from_syscall("fchmod"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> fchown(int fd, uid_t uid, gid_t gid)
|
||||
{
|
||||
if (::fchown(fd, uid, gid) < 0)
|
||||
return Error::from_syscall("fchown"sv, -errno);
|
||||
return Error::from_syscall("fchown"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
|
||||
{
|
||||
if (!pathname.characters_without_null_termination())
|
||||
return Error::from_syscall("chown"sv, -EFAULT);
|
||||
return Error::from_syscall("chown"sv, EFAULT);
|
||||
|
||||
ByteString path = pathname;
|
||||
if (::lchown(path.characters(), uid, gid) < 0)
|
||||
return Error::from_syscall("lchown"sv, -errno);
|
||||
return Error::from_syscall("lchown"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -375,7 +375,7 @@ static ALWAYS_INLINE ErrorOr<pid_t> posix_spawn_wrapper(StringView path, posix_s
|
|||
{
|
||||
pid_t child_pid;
|
||||
if ((errno = spawn_function(&child_pid, path.to_byte_string().characters(), file_actions, attr, arguments, envp)))
|
||||
return Error::from_syscall(function_name, -errno);
|
||||
return Error::from_syscall(function_name, errno);
|
||||
return child_pid;
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ ErrorOr<off_t> lseek(int fd, off_t offset, int whence)
|
|||
{
|
||||
off_t rc = ::lseek(fd, offset, whence);
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("lseek"sv, -errno);
|
||||
return Error::from_syscall("lseek"sv, errno);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -402,7 +402,7 @@ ErrorOr<WaitPidResult> waitpid(pid_t waitee, int options)
|
|||
int wstatus;
|
||||
pid_t pid = ::waitpid(waitee, &wstatus, options);
|
||||
if (pid < 0)
|
||||
return Error::from_syscall("waitpid"sv, -errno);
|
||||
return Error::from_syscall("waitpid"sv, errno);
|
||||
return WaitPidResult { pid, wstatus };
|
||||
}
|
||||
|
||||
|
@ -410,7 +410,7 @@ ErrorOr<bool> isatty(int fd)
|
|||
{
|
||||
int rc = ::isatty(fd);
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("isatty"sv, -errno);
|
||||
return Error::from_syscall("isatty"sv, errno);
|
||||
return rc == 1;
|
||||
}
|
||||
|
||||
|
@ -419,7 +419,7 @@ ErrorOr<void> link(StringView old_path, StringView new_path)
|
|||
ByteString old_path_string = old_path;
|
||||
ByteString new_path_string = new_path;
|
||||
if (::link(old_path_string.characters(), new_path_string.characters()) < 0)
|
||||
return Error::from_syscall("link"sv, -errno);
|
||||
return Error::from_syscall("link"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -428,7 +428,7 @@ ErrorOr<void> symlink(StringView target, StringView link_path)
|
|||
ByteString target_string = target;
|
||||
ByteString link_path_string = link_path;
|
||||
if (::symlink(target_string.characters(), link_path_string.characters()) < 0)
|
||||
return Error::from_syscall("symlink"sv, -errno);
|
||||
return Error::from_syscall("symlink"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ ErrorOr<void> mkdir(StringView path, mode_t mode)
|
|||
return Error::from_errno(EFAULT);
|
||||
ByteString path_string = path;
|
||||
if (::mkdir(path_string.characters(), mode) < 0)
|
||||
return Error::from_syscall("mkdir"sv, -errno);
|
||||
return Error::from_syscall("mkdir"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -449,7 +449,7 @@ ErrorOr<void> chdir(StringView path)
|
|||
|
||||
ByteString path_string = path;
|
||||
if (::chdir(path_string.characters()) < 0)
|
||||
return Error::from_syscall("chdir"sv, -errno);
|
||||
return Error::from_syscall("chdir"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -460,7 +460,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 {};
|
||||
}
|
||||
|
||||
|
@ -468,7 +468,7 @@ ErrorOr<int> mkstemp(Span<char> pattern)
|
|||
{
|
||||
int fd = ::mkstemp(pattern.data());
|
||||
if (fd < 0)
|
||||
return Error::from_syscall("mkstemp"sv, -errno);
|
||||
return Error::from_syscall("mkstemp"sv, errno);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -490,7 +490,7 @@ ErrorOr<void> rename(StringView old_path, StringView new_path)
|
|||
ByteString old_path_string = old_path;
|
||||
ByteString new_path_string = new_path;
|
||||
if (::rename(old_path_string.characters(), new_path_string.characters()) < 0)
|
||||
return Error::from_syscall("rename"sv, -errno);
|
||||
return Error::from_syscall("rename"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -501,7 +501,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 {};
|
||||
}
|
||||
|
||||
|
@ -516,7 +516,7 @@ ErrorOr<void> utimensat(int fd, StringView path, struct timespec const times[2],
|
|||
|
||||
// Note the explicit null terminators above.
|
||||
if (::utimensat(fd, builder.string_view().characters_without_null_termination(), times, flag) < 0)
|
||||
return Error::from_syscall("utimensat"sv, -errno);
|
||||
return Error::from_syscall("utimensat"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -524,7 +524,7 @@ ErrorOr<struct utsname> uname()
|
|||
{
|
||||
struct utsname uts;
|
||||
if (::uname(&uts) < 0)
|
||||
return Error::from_syscall("uname"sv, -errno);
|
||||
return Error::from_syscall("uname"sv, errno);
|
||||
return uts;
|
||||
}
|
||||
|
||||
|
@ -532,21 +532,21 @@ ErrorOr<int> socket(int domain, int type, int protocol)
|
|||
{
|
||||
auto fd = ::socket(domain, type, protocol);
|
||||
if (fd < 0)
|
||||
return Error::from_syscall("socket"sv, -errno);
|
||||
return Error::from_syscall("socket"sv, errno);
|
||||
return fd;
|
||||
}
|
||||
|
||||
ErrorOr<void> bind(int sockfd, struct sockaddr const* address, socklen_t address_length)
|
||||
{
|
||||
if (::bind(sockfd, address, address_length) < 0)
|
||||
return Error::from_syscall("bind"sv, -errno);
|
||||
return Error::from_syscall("bind"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> listen(int sockfd, int backlog)
|
||||
{
|
||||
if (::listen(sockfd, backlog) < 0)
|
||||
return Error::from_syscall("listen"sv, -errno);
|
||||
return Error::from_syscall("listen"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -554,14 +554,14 @@ ErrorOr<int> accept(int sockfd, struct sockaddr* address, socklen_t* address_len
|
|||
{
|
||||
auto fd = ::accept(sockfd, address, address_length);
|
||||
if (fd < 0)
|
||||
return Error::from_syscall("accept"sv, -errno);
|
||||
return Error::from_syscall("accept"sv, errno);
|
||||
return fd;
|
||||
}
|
||||
|
||||
ErrorOr<void> connect(int sockfd, struct sockaddr const* address, socklen_t address_length)
|
||||
{
|
||||
if (::connect(sockfd, address, address_length) < 0)
|
||||
return Error::from_syscall("connect"sv, -errno);
|
||||
return Error::from_syscall("connect"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -569,7 +569,7 @@ ErrorOr<ssize_t> send(int sockfd, void const* buffer, size_t buffer_length, int
|
|||
{
|
||||
auto sent = ::send(sockfd, buffer, buffer_length, flags);
|
||||
if (sent < 0)
|
||||
return Error::from_syscall("send"sv, -errno);
|
||||
return Error::from_syscall("send"sv, errno);
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
@ -577,7 +577,7 @@ ErrorOr<ssize_t> sendmsg(int sockfd, const struct msghdr* message, int flags)
|
|||
{
|
||||
auto sent = ::sendmsg(sockfd, message, flags);
|
||||
if (sent < 0)
|
||||
return Error::from_syscall("sendmsg"sv, -errno);
|
||||
return Error::from_syscall("sendmsg"sv, errno);
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
@ -585,7 +585,7 @@ ErrorOr<ssize_t> sendto(int sockfd, void const* source, size_t source_length, in
|
|||
{
|
||||
auto sent = ::sendto(sockfd, source, source_length, flags, destination, destination_length);
|
||||
if (sent < 0)
|
||||
return Error::from_syscall("sendto"sv, -errno);
|
||||
return Error::from_syscall("sendto"sv, errno);
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
@ -593,7 +593,7 @@ ErrorOr<ssize_t> recv(int sockfd, void* buffer, size_t length, int flags)
|
|||
{
|
||||
auto received = ::recv(sockfd, buffer, length, flags);
|
||||
if (received < 0)
|
||||
return Error::from_syscall("recv"sv, -errno);
|
||||
return Error::from_syscall("recv"sv, errno);
|
||||
return received;
|
||||
}
|
||||
|
||||
|
@ -601,7 +601,7 @@ ErrorOr<ssize_t> recvmsg(int sockfd, struct msghdr* message, int flags)
|
|||
{
|
||||
auto received = ::recvmsg(sockfd, message, flags);
|
||||
if (received < 0)
|
||||
return Error::from_syscall("recvmsg"sv, -errno);
|
||||
return Error::from_syscall("recvmsg"sv, errno);
|
||||
return received;
|
||||
}
|
||||
|
||||
|
@ -609,7 +609,7 @@ ErrorOr<ssize_t> recvfrom(int sockfd, void* buffer, size_t buffer_length, int fl
|
|||
{
|
||||
auto received = ::recvfrom(sockfd, buffer, buffer_length, flags, address, address_length);
|
||||
if (received < 0)
|
||||
return Error::from_syscall("recvfrom"sv, -errno);
|
||||
return Error::from_syscall("recvfrom"sv, errno);
|
||||
return received;
|
||||
}
|
||||
|
||||
|
@ -620,7 +620,7 @@ ErrorOr<AddressInfoVector> getaddrinfo(char const* nodename, char const* servnam
|
|||
int const rc = ::getaddrinfo(nodename, servname, &hints, &results);
|
||||
if (rc != 0) {
|
||||
if (rc == EAI_SYSTEM) {
|
||||
return Error::from_syscall("getaddrinfo"sv, -errno);
|
||||
return Error::from_syscall("getaddrinfo"sv, errno);
|
||||
}
|
||||
|
||||
auto const* error_string = gai_strerror(rc);
|
||||
|
@ -638,35 +638,35 @@ ErrorOr<AddressInfoVector> getaddrinfo(char const* nodename, char const* servnam
|
|||
ErrorOr<void> getsockopt(int sockfd, int level, int option, void* value, socklen_t* value_size)
|
||||
{
|
||||
if (::getsockopt(sockfd, level, option, value, value_size) < 0)
|
||||
return Error::from_syscall("getsockopt"sv, -errno);
|
||||
return Error::from_syscall("getsockopt"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> setsockopt(int sockfd, int level, int option, void const* value, socklen_t value_size)
|
||||
{
|
||||
if (::setsockopt(sockfd, level, option, value, value_size) < 0)
|
||||
return Error::from_syscall("setsockopt"sv, -errno);
|
||||
return Error::from_syscall("setsockopt"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> getsockname(int sockfd, struct sockaddr* address, socklen_t* address_length)
|
||||
{
|
||||
if (::getsockname(sockfd, address, address_length) < 0)
|
||||
return Error::from_syscall("getsockname"sv, -errno);
|
||||
return Error::from_syscall("getsockname"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> getpeername(int sockfd, struct sockaddr* address, socklen_t* address_length)
|
||||
{
|
||||
if (::getpeername(sockfd, address, address_length) < 0)
|
||||
return Error::from_syscall("getpeername"sv, -errno);
|
||||
return Error::from_syscall("getpeername"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> socketpair(int domain, int type, int protocol, int sv[2])
|
||||
{
|
||||
if (::socketpair(domain, type, protocol, sv) < 0)
|
||||
return Error::from_syscall("socketpair"sv, -errno);
|
||||
return Error::from_syscall("socketpair"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -676,10 +676,10 @@ ErrorOr<Array<int, 2>> pipe2(int flags)
|
|||
|
||||
#if defined(__unix__)
|
||||
if (::pipe2(fds.data(), flags) < 0)
|
||||
return Error::from_syscall("pipe2"sv, -errno);
|
||||
return Error::from_syscall("pipe2"sv, errno);
|
||||
#else
|
||||
if (::pipe(fds.data()) < 0)
|
||||
return Error::from_syscall("pipe2"sv, -errno);
|
||||
return Error::from_syscall("pipe2"sv, errno);
|
||||
|
||||
// Ensure we don't leak the fds if any of the system calls below fail.
|
||||
AK::ArmedScopeGuard close_fds { [&]() {
|
||||
|
@ -705,13 +705,13 @@ ErrorOr<Array<int, 2>> pipe2(int flags)
|
|||
ErrorOr<void> access(StringView pathname, int mode, int flags)
|
||||
{
|
||||
if (pathname.is_null())
|
||||
return Error::from_syscall("access"sv, -EFAULT);
|
||||
return Error::from_syscall("access"sv, EFAULT);
|
||||
|
||||
ByteString path_string = pathname;
|
||||
(void)flags;
|
||||
|
||||
if (::access(path_string.characters(), mode) < 0)
|
||||
return Error::from_syscall("access"sv, -errno);
|
||||
return Error::from_syscall("access"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -731,7 +731,7 @@ ErrorOr<ByteString> readlink(StringView pathname)
|
|||
ByteString path_string = pathname;
|
||||
int rc = ::readlink(path_string.characters(), data, sizeof(data));
|
||||
if (rc == -1)
|
||||
return Error::from_syscall("readlink"sv, -errno);
|
||||
return Error::from_syscall("readlink"sv, errno);
|
||||
|
||||
return ByteString(data, rc);
|
||||
#endif
|
||||
|
@ -741,7 +741,7 @@ ErrorOr<int> poll(Span<struct pollfd> poll_fds, int timeout)
|
|||
{
|
||||
auto const rc = ::poll(poll_fds.data(), poll_fds.size(), timeout);
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("poll"sv, -errno);
|
||||
return Error::from_syscall("poll"sv, errno);
|
||||
return { rc };
|
||||
}
|
||||
|
||||
|
@ -762,18 +762,18 @@ ErrorOr<ByteString> current_executable_path()
|
|||
auto ret = ::readlink("/proc/self/exe", path, sizeof(path) - 1);
|
||||
// Ignore error if it wasn't a symlink
|
||||
if (ret == -1 && errno != EINVAL)
|
||||
return Error::from_syscall("readlink"sv, -errno);
|
||||
return Error::from_syscall("readlink"sv, errno);
|
||||
#elif defined(AK_OS_GNU_HURD)
|
||||
// We could read /proc/self/exe, but why rely on procfs being mounted
|
||||
// if we can do the same thing procfs does and ask the proc server directly?
|
||||
process_t proc = getproc();
|
||||
if (!MACH_PORT_VALID(proc))
|
||||
return Error::from_syscall("getproc"sv, -errno);
|
||||
return Error::from_syscall("getproc"sv, errno);
|
||||
kern_return_t err = proc_get_exe(proc, getpid(), path);
|
||||
mach_port_deallocate(mach_task_self(), proc);
|
||||
if (err) {
|
||||
__hurd_fail(static_cast<error_t>(err));
|
||||
return Error::from_syscall("proc_get_exe"sv, -errno);
|
||||
return Error::from_syscall("proc_get_exe"sv, errno);
|
||||
}
|
||||
#elif defined(AK_OS_DRAGONFLY)
|
||||
return TRY(readlink("/proc/curproc/file"sv));
|
||||
|
@ -783,12 +783,12 @@ ErrorOr<ByteString> current_executable_path()
|
|||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
|
||||
size_t len = sizeof(path);
|
||||
if (sysctl(mib, 4, path, &len, nullptr, 0) < 0)
|
||||
return Error::from_syscall("sysctl"sv, -errno);
|
||||
return Error::from_syscall("sysctl"sv, errno);
|
||||
#elif defined(AK_OS_NETBSD)
|
||||
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
|
||||
size_t len = sizeof(path);
|
||||
if (sysctl(mib, 4, path, &len, nullptr, 0) < 0)
|
||||
return Error::from_syscall("sysctl"sv, -errno);
|
||||
return Error::from_syscall("sysctl"sv, errno);
|
||||
#elif defined(AK_OS_MACOS) || defined(AK_OS_IOS)
|
||||
u32 size = sizeof(path);
|
||||
auto ret = _NSGetExecutablePath(path, &size);
|
||||
|
@ -819,7 +819,7 @@ ErrorOr<rlimit> get_resource_limits(int resource)
|
|||
rlimit limits;
|
||||
|
||||
if (::getrlimit(resource, &limits) != 0)
|
||||
return Error::from_syscall("getrlimit"sv, -errno);
|
||||
return Error::from_syscall("getrlimit"sv, errno);
|
||||
|
||||
return limits;
|
||||
}
|
||||
|
@ -830,7 +830,7 @@ ErrorOr<void> set_resource_limits(int resource, rlim_t limit)
|
|||
limits.rlim_cur = min(limit, limits.rlim_max);
|
||||
|
||||
if (::setrlimit(resource, &limits) != 0)
|
||||
return Error::from_syscall("setrlimit"sv, -errno);
|
||||
return Error::from_syscall("setrlimit"sv, errno);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -849,7 +849,7 @@ bool is_socket(int fd)
|
|||
ErrorOr<void> sleep_ms(u32 milliseconds)
|
||||
{
|
||||
if (usleep(1000 * milliseconds) != 0)
|
||||
return Error::from_syscall("usleep"sv, -errno);
|
||||
return Error::from_syscall("usleep"sv, errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {};
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ ErrorOr<ByteString> real_path(StringView path)
|
|||
ScopeGuard free_path = [real_path]() { free(real_path); };
|
||||
|
||||
if (!real_path)
|
||||
return Error::from_syscall("realpath"sv, -errno);
|
||||
return Error::from_syscall("realpath"sv, errno);
|
||||
|
||||
return ByteString { real_path, strlen(real_path) };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue