From 701ef172272eca44e95a71724ac18cd61b5d2316 Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Tue, 16 Nov 2021 10:05:35 -0500 Subject: [PATCH] Move strftime to daily_filename_format_calculator --- include/spdlog/details/fmt_helper.h | 17 ----------------- include/spdlog/sinks/daily_file_sink.h | 24 ++++++++++++++++++++++-- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/spdlog/details/fmt_helper.h b/include/spdlog/details/fmt_helper.h index 0a8de309..25976f50 100644 --- a/include/spdlog/details/fmt_helper.h +++ b/include/spdlog/details/fmt_helper.h @@ -164,23 +164,6 @@ inline ToDuration time_fraction(log_clock::time_point tp) return duration_cast(duration) - duration_cast(secs); } -inline size_t strftime(char *str, size_t count, const char *format, const std::tm *time) -{ - // Assign to a pointer to suppress GCCs -Wformat-nonliteral - // First assign the nullptr to suppress -Wsuggest-attribute=format - std::size_t (*strftime)(char*, std::size_t, const char*, const std::tm*) = nullptr; - strftime = std::strftime; - return strftime(str, count, format, time); -} - -inline size_t strftime(wchar_t *str, size_t count, const wchar_t *format, const std::tm *time) -{ - // See above - std::size_t (*wcsftime)(wchar_t*, std::size_t, const wchar_t*, const std::tm*) = nullptr; - wcsftime = std::wcsftime; - return wcsftime(str, count, format, time); -} - } // namespace fmt_helper } // namespace details } // namespace spdlog diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index 8cdf35c1..447f2529 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -62,7 +62,7 @@ struct daily_filename_format_calculator buf.resize(MIN_SIZE); for (;;) { - size_t count = details::fmt_helper::strftime(buf.data(), buf.size(), tm_format.c_str(), &now_tm); + size_t count = strftime(buf.data(), buf.size(), tm_format.c_str(), &now_tm); if (count != 0) { // Remove the extra space. @@ -87,7 +87,7 @@ struct daily_filename_format_calculator for (;;) { size_t size = buf.capacity() - start; - size_t count = details::fmt_helper::strftime(&buf[start], size, &tm_format[0], &now_tm); + size_t count = strftime(&buf[start], size, &tm_format[0], &now_tm); if (count != 0) { // Remove the extra space. @@ -101,6 +101,26 @@ struct daily_filename_format_calculator return fmt::to_string(buf); #endif } + +private: +#if defined __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + + static size_t strftime(char *str, size_t count, const char *format, const std::tm *time) + { + return std::strftime(str, count, format, time); + } + + static size_t strftime(wchar_t *str, size_t count, const wchar_t *format, const std::tm *time) + { + return std::wcsftime(str, count, format, time); + } + +#if defined(__GNUC__) +# pragma GCC diagnostic pop +#endif }; /*