From dceed080585d0589bb41a9afc47b7e173f27685f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 10 May 2025 16:24:35 -0400 Subject: [PATCH] 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. --- AK/Error.h | 8 +- Libraries/LibCore/Directory.cpp | 2 +- Libraries/LibCore/LocalServer.cpp | 2 +- Libraries/LibCore/Process.cpp | 14 +-- Libraries/LibCore/System.cpp | 152 ++++++++++++------------- Libraries/LibCore/SystemWindows.cpp | 20 ++-- Libraries/LibFileSystem/FileSystem.cpp | 2 +- 7 files changed, 100 insertions(+), 100 deletions(-) diff --git a/AK/Error.h b/AK/Error.h index d7e8c28d60e..6db779c5a49 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -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) { } diff --git a/Libraries/LibCore/Directory.cpp b/Libraries/LibCore/Directory.cpp index 61807d14941..fb4e61899b2 100644 --- a/Libraries/LibCore/Directory.cpp +++ b/Libraries/LibCore/Directory.cpp @@ -33,7 +33,7 @@ Directory::~Directory() ErrorOr 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 {}; } diff --git a/Libraries/LibCore/LocalServer.cpp b/Libraries/LibCore/LocalServer.cpp index 9efc53dee84..d8cc3dc3d3e 100644 --- a/Libraries/LibCore/LocalServer.cpp +++ b/Libraries/LibCore/LocalServer.cpp @@ -120,7 +120,7 @@ ErrorOr> 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) diff --git a/Libraries/LibCore/Process.cpp b/Libraries/LibCore/Process.cpp index ce784b3d645..cb9f95d080b 100644 --- a/Libraries/LibCore/Process.cpp +++ b/Libraries/LibCore/Process.cpp @@ -182,7 +182,7 @@ ErrorOr 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 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 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 Process::is_being_debugged() mach_port_deallocate(mach_task_self(), proc); if (err) { __hurd_fail(static_cast(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 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 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); diff --git a/Libraries/LibCore/System.cpp b/Libraries/LibCore/System.cpp index 2f29059840f..7d0b94a2f70 100644 --- a/Libraries/LibCore/System.cpp +++ b/Libraries/LibCore/System.cpp @@ -65,7 +65,7 @@ ErrorOr 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 accept4(int sockfd, sockaddr* address, socklen_t* address_length, i ErrorOr 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 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 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 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 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 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 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 open(StringView path, int options, mode_t mode) ErrorOr 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 close(int fd) { if (::close(fd) < 0) - return Error::from_syscall("close"sv, -errno); + return Error::from_syscall("close"sv, errno); return {}; } ErrorOr 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 mkstemp(Span 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 getaddrinfo(char const* nodename, char const* servnam ErrorOr 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 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 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 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 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> 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> pipe2(int flags) ErrorOr 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 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 poll(Span 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 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(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 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 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 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 sleep_ms(u32 milliseconds) { if (usleep(1000 * milliseconds) != 0) - return Error::from_syscall("usleep"sv, -errno); + return Error::from_syscall("usleep"sv, errno); return {}; } diff --git a/Libraries/LibCore/SystemWindows.cpp b/Libraries/LibCore/SystemWindows.cpp index b6a0e7e03c2..a791a5f2138 100644 --- a/Libraries/LibCore/SystemWindows.cpp +++ b/Libraries/LibCore/SystemWindows.cpp @@ -45,7 +45,7 @@ ErrorOr 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 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 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 getcwd() ErrorOr 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 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 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 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 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 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 {}; } diff --git a/Libraries/LibFileSystem/FileSystem.cpp b/Libraries/LibFileSystem/FileSystem.cpp index c59c9127c19..d860e6007d8 100644 --- a/Libraries/LibFileSystem/FileSystem.cpp +++ b/Libraries/LibFileSystem/FileSystem.cpp @@ -56,7 +56,7 @@ ErrorOr 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) }; }