From b8228c249975306f1d35a43d79a99d4c6dc5f116 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 4 Mar 2025 23:39:03 +0800 Subject: clang-format & clang-tidy --- src/FileDescriptor.cpp | 73 +++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) (limited to 'src/FileDescriptor.cpp') diff --git a/src/FileDescriptor.cpp b/src/FileDescriptor.cpp index 8592f42..6f17f2a 100644 --- a/src/FileDescriptor.cpp +++ b/src/FileDescriptor.cpp @@ -1,89 +1,88 @@ #include -#include #include +#include #include #include #include using namespace Hyprutils::OS; -CFileDescriptor::CFileDescriptor(int const fd) : m_fd(fd) {} +CFileDescriptor::CFileDescriptor(int const fd) + : m_fd(fd) {} -CFileDescriptor::CFileDescriptor(CFileDescriptor&& other) : m_fd(std::exchange(other.m_fd, -1)) {} +CFileDescriptor::CFileDescriptor(CFileDescriptor &&other) noexcept + : m_fd(std::exchange(other.m_fd, -1)) {} -CFileDescriptor& CFileDescriptor::operator=(CFileDescriptor&& other) { - if (this == &other) // Shit will go haywire if there is duplicate ownership - abort(); +CFileDescriptor &CFileDescriptor::operator=(CFileDescriptor &&other) noexcept { + if (this == &other) // Shit will go haywire if there is duplicate ownership + abort(); - reset(); - m_fd = std::exchange(other.m_fd, -1); - return *this; + reset(); + m_fd = std::exchange(other.m_fd, -1); + return *this; } CFileDescriptor::~CFileDescriptor() { - reset(); + reset(); } bool CFileDescriptor::isValid() const { - return m_fd != -1; + return m_fd != -1; } int CFileDescriptor::get() const { - return m_fd; + return m_fd; } int CFileDescriptor::getFlags() const { - return fcntl(m_fd, F_GETFD); + return fcntl(m_fd, F_GETFD); } bool CFileDescriptor::setFlags(int flags) { - if (fcntl(m_fd, F_SETFD, flags) == -1) - return false; - - return true; + return fcntl(m_fd, F_SETFD, flags) != -1; } int CFileDescriptor::take() { - return std::exchange(m_fd, -1); + return std::exchange(m_fd, -1); } void CFileDescriptor::reset() { - if (m_fd != -1) { - close(m_fd); - m_fd = -1; - } + if (m_fd != -1) { + close(m_fd); + m_fd = -1; + } } CFileDescriptor CFileDescriptor::duplicate(int flags) const { - if (m_fd == -1) - return {}; + if (m_fd == -1) + return {}; - return CFileDescriptor{fcntl(m_fd, flags, 0)}; + return CFileDescriptor{fcntl(m_fd, flags, 0)}; } bool CFileDescriptor::isClosed() const { - return isClosed(m_fd); + return isClosed(m_fd); } bool CFileDescriptor::isReadable() const { - return isReadable(m_fd); + return isReadable(m_fd); } bool CFileDescriptor::isClosed(int fd) { - pollfd pfd = { - .fd = fd, - .events = POLLIN, - .revents = 0, - }; + pollfd pfd = { + .fd = fd, + .events = POLLIN, + .revents = 0, + }; - if (poll(&pfd, 1, 0) < 0) - return true; + if (poll(&pfd, 1, 0) < 0) + return true; - return pfd.revents & (POLLHUP | POLLERR); + return pfd.revents & (POLLHUP | POLLERR); } bool CFileDescriptor::isReadable(int fd) { - pollfd pfd = {.fd = fd, .events = POLLIN, .revents = 0}; + pollfd pfd = {.fd = fd, .events = POLLIN, .revents = 0}; - return poll(&pfd, 1, 0) > 0 && (pfd.revents & POLLIN); + return poll(&pfd, 1, 0) > 0 && (pfd.revents & POLLIN); } -- cgit v1.2.3