diff --git a/include/utils/file.hpp b/include/utils/file.hpp index 8f894a8b..f39f1991 100644 --- a/include/utils/file.hpp +++ b/include/utils/file.hpp @@ -66,8 +66,8 @@ class fd_streambuf : public std::streambuf { private: file_descriptor m_fd; - char m_out[BUFSIZ]{'\0'}; - char m_in[BUFSIZ - 1]{'\0'}; + char m_out[BUFSIZ]{}; + char m_in[BUFSIZ - 1]{}; }; template diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 9e014983..aada0aef 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -272,7 +272,7 @@ void controller::read_events() { // Process event on the internal fd if (m_queuefd[PIPE_READ] && FD_ISSET(static_cast(*m_queuefd[PIPE_READ]), &readfds)) { - char buffer[BUFSIZ]{'\0'}; + char buffer[BUFSIZ]; if (read(static_cast(*m_queuefd[PIPE_READ]), &buffer, BUFSIZ) == -1) { m_log.err("Failed to read from eventpipe (err: %s)", strerror(errno)); } diff --git a/src/utils/file.cpp b/src/utils/file.cpp index ebf6158c..c0cb9f63 100644 --- a/src/utils/file.cpp +++ b/src/utils/file.cpp @@ -52,8 +52,8 @@ file_descriptor::file_descriptor(const string& path, int flags) { } file_descriptor::file_descriptor(int fd) : m_fd(fd) { - if (!*this) { - throw system_error("Given file descriptor is not valid"); + if (m_fd != -1 && !*this) { + throw system_error("Given file descriptor (" + to_string(m_fd) + ") is not valid"); } } @@ -87,9 +87,7 @@ file_descriptor::operator bool() const { } void file_descriptor::close() { - if (m_fd == -1) { - return; - } else if (::close(m_fd) == -1) { + if (m_fd != -1 && ::close(m_fd) == -1) { throw system_error("Failed to close file descriptor"); } m_fd = -1; @@ -98,10 +96,12 @@ void file_descriptor::close() { // }}} // implementation of file_streambuf {{{ -fd_streambuf::fd_streambuf(int fd) : m_fd(fd) {} +fd_streambuf::fd_streambuf(int fd) : m_fd(-1) { + open(fd); +} fd_streambuf::~fd_streambuf() { - sync(); + close(); } fd_streambuf::operator int() { @@ -113,7 +113,7 @@ fd_streambuf::operator int() const { void fd_streambuf::open(int fd) { if (m_fd) { - sync(); + close(); } m_fd = fd; setg(m_in, m_in, m_in); diff --git a/src/x11/fonts.cpp b/src/x11/fonts.cpp index ac879306..ec1266fd 100644 --- a/src/x11/fonts.cpp +++ b/src/x11/fonts.cpp @@ -1,3 +1,4 @@ +#include "x11/fonts.hpp" #include "components/logger.hpp" #include "errors.hpp" #include "utils/color.hpp" @@ -5,7 +6,6 @@ #include "utils/memory.hpp" #include "x11/connection.hpp" #include "x11/draw.hpp" -#include "x11/fonts.hpp" POLYBAR_NS diff --git a/src/x11/window.cpp b/src/x11/window.cpp index 4c4518dd..05c31113 100644 --- a/src/x11/window.cpp +++ b/src/x11/window.cpp @@ -1,11 +1,11 @@ #include #include "components/types.hpp" +#include "utils/memory.hpp" #include "x11/atoms.hpp" #include "x11/connection.hpp" #include "x11/extensions/randr.hpp" #include "x11/window.hpp" -#include "utils/memory.hpp" POLYBAR_NS