refactor(fd_streambuf): Cleanup
This commit is contained in:
parent
acb9ed910d
commit
dd960cc5b5
@ -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 <typename StreamType = std::ostream>
|
||||
|
@ -272,7 +272,7 @@ void controller::read_events() {
|
||||
|
||||
// Process event on the internal fd
|
||||
if (m_queuefd[PIPE_READ] && FD_ISSET(static_cast<int>(*m_queuefd[PIPE_READ]), &readfds)) {
|
||||
char buffer[BUFSIZ]{'\0'};
|
||||
char buffer[BUFSIZ];
|
||||
if (read(static_cast<int>(*m_queuefd[PIPE_READ]), &buffer, BUFSIZ) == -1) {
|
||||
m_log.err("Failed to read from eventpipe (err: %s)", strerror(errno));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include <xcb/xcb_icccm.h>
|
||||
|
||||
#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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user