From c5274a56b8a306fd184e80bd023824e623c56c27 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Sun, 19 Nov 2023 17:26:04 +0100 Subject: [PATCH] print errno --- Log.cpp | 7 +++++++ Log.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/Log.cpp b/Log.cpp index 3ba56d7..4f54549 100644 --- a/Log.cpp +++ b/Log.cpp @@ -2,6 +2,7 @@ #include #include // date/time +#include #include // ofstream (logging to file) #include // std::ostream, std::cout, std::cin #include // std::unique_ptr @@ -284,6 +285,12 @@ void setColoredOutput(bool enabled) { dynamic_cast(*outputs.at(0)).setColoredOutput(enabled); // has to exist } +const PrintErrno err; + +std::ostream& operator<<(std::ostream& str, const PrintErrno&) { + return str << strerror(errno) << " (" << errno << ')'; +} + std::ostream& operator<<(std::ostream& str, const FileSize& fs) { static const char PREFIX[] {' ', 'K', 'M', 'G', 'T', 'P', 'E'}; static const uint_fast8_t PREFIXCOUNT = 7; diff --git a/Log.h b/Log.h index 144fb58..b426a0e 100644 --- a/Log.h +++ b/Log.h @@ -127,6 +127,12 @@ private: friend std::ostream& operator<<(std::ostream& str, const FileSize& fs); }; +struct PrintErrno {}; + +extern const PrintErrno err; + +std::ostream& operator<<(std::ostream& str, const PrintErrno&); + std::ostream& operator<<(std::ostream& str, const FileSize& fs); // copy Level values in Log namespace