From 0e5c4b9de458e570fa41faa717488c6c044b14ca Mon Sep 17 00:00:00 2001 From: Artem Martynovich Date: Tue, 14 Jul 2015 02:13:16 +0600 Subject: [PATCH] Fix Unix build. Use S("...") instead of L"..." for better compatibility. --- include/spdlog/common.h | 3 ++- include/spdlog/details/format.h | 11 ++++++----- include/spdlog/details/os.h | 4 ++-- include/spdlog/details/spdlog_impl.h | 8 ++++---- include/spdlog/sinks/file_sinks.h | 6 +++--- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 8e601547..d23a86bc 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -39,8 +39,9 @@ #ifdef WIN32 typedef std::wstring tstring; typedef wchar_t tchar; +#define S(s) L ## s #else -#define L +#define S(s) s typedef std::string tstring; typedef char tchar; #endif diff --git a/include/spdlog/details/format.h b/include/spdlog/details/format.h index f1cfd48b..af584b7f 100644 --- a/include/spdlog/details/format.h +++ b/include/spdlog/details/format.h @@ -2638,6 +2638,12 @@ public: typedef BasicMemoryWriter MemoryWriter; typedef BasicMemoryWriter WMemoryWriter; +#ifdef WIN32 +#define TMemoryWriter WMemoryWriter +#else +#define TMemoryWriter MemoryWriter +#endif + /** \rst This class template provides operations for formatting and writing data @@ -2648,11 +2654,6 @@ Any write method will throw ``std::runtime_error`` if the output doesn't fit into the array. You can use one of the following typedefs for common character types: -#ifdef WIN32 -#define TMemoryWriter WMemoryWriter -#else -#define TMemoryWriter MemoryWriter -#endif +--------------+---------------------------+ | Type | Definition | diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 1d010937..61e05682 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -147,7 +147,7 @@ constexpr inline unsigned short eol_size() #endif //fopen_s on non windows for writing -inline int fopen_s(FILE** fp, const tstring& filename, tchar* mode) +inline int fopen_s(FILE** fp, const tstring& filename, const tchar* mode) { #ifdef _WIN32 *fp = _wfsopen((filename.c_str()), mode, _SH_DENYWR); @@ -172,7 +172,7 @@ inline int rename(const tchar* filename1, const tchar* filename2) #ifdef _WIN32 return _wrename(filename1, filename2); #else - return std::remove(filename1, filename2); + return std::remove(filename1); #endif } diff --git a/include/spdlog/details/spdlog_impl.h b/include/spdlog/details/spdlog_impl.h index 18cd5b65..2530b596 100644 --- a/include/spdlog/details/spdlog_impl.h +++ b/include/spdlog/details/spdlog_impl.h @@ -50,22 +50,22 @@ inline void spdlog::drop(const std::string &name) // Create multi/single threaded rotating file logger inline std::shared_ptr spdlog::rotating_logger_mt(const std::string& logger_name, const tstring& filename, size_t max_file_size, size_t max_files, bool force_flush) { - return create(logger_name, filename, L"txt", max_file_size, max_files, force_flush); + return create(logger_name, filename, S("txt"), max_file_size, max_files, force_flush); } inline std::shared_ptr spdlog::rotating_logger_st(const std::string& logger_name, const tstring& filename, size_t max_file_size, size_t max_files, bool force_flush) { - return create(logger_name, filename, L"txt", max_file_size, max_files, force_flush); + return create(logger_name, filename, S("txt"), max_file_size, max_files, force_flush); } // Create file logger which creates new file at midnight): inline std::shared_ptr spdlog::daily_logger_mt(const std::string& logger_name, const tstring& filename, int hour, int minute, bool force_flush) { - return create(logger_name, filename, L"txt", hour, minute, force_flush); + return create(logger_name, filename, S("txt"), hour, minute, force_flush); } inline std::shared_ptr spdlog::daily_logger_st(const std::string& logger_name, const tstring& filename, int hour, int minute, bool force_flush) { - return create(logger_name, filename, L"txt", hour, minute, force_flush); + return create(logger_name, filename, S("txt"), hour, minute, force_flush); } diff --git a/include/spdlog/sinks/file_sinks.h b/include/spdlog/sinks/file_sinks.h index 5f980ef3..12e36a75 100644 --- a/include/spdlog/sinks/file_sinks.h +++ b/include/spdlog/sinks/file_sinks.h @@ -107,9 +107,9 @@ private: { fmt::TMemoryWriter w; if (index) - w.write(L"{}.{}.{}", filename, index, extension); + w.write(S("{}.{}.{}"), filename, index, extension); else - w.write(L"{}.{}", filename, extension); + w.write(S("{}.{}"), filename, extension); return w.str(); } @@ -215,7 +215,7 @@ private: { std::tm tm = spdlog::details::os::localtime(); fmt::TMemoryWriter w; - w.write(L"{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}.{}", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, extension); + w.write(S("{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}.{}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, extension); return w.str(); }