From 787aa4669337a51d1f24feb40a4e6478fcf857c1 Mon Sep 17 00:00:00 2001 From: Artem Martynovich Date: Tue, 21 Jul 2015 17:32:53 +0600 Subject: [PATCH] Disable usage of wchar_t in tests. --- include/spdlog/common.h | 6 +++++- include/spdlog/details/format.h | 2 +- include/spdlog/details/os.h | 12 ++++++++---- include/spdlog/tweakme.h | 6 ++++++ tests/includes.h | 1 + 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index d23a86bc..dd05f1b0 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -36,7 +36,11 @@ #define SPDLOG_NOEXCEPT throw() #endif -#ifdef WIN32 +#if !defined(SPDLOG_NO_WCHAR) && defined(WIN32) +#define SPDLOG_USE_WCHAR +#endif + +#if defined(WIN32) && defined(SPDLOG_USE_WCHAR) typedef std::wstring tstring; typedef wchar_t tchar; #define S(s) L ## s diff --git a/include/spdlog/details/format.h b/include/spdlog/details/format.h index af584b7f..aaeb011d 100644 --- a/include/spdlog/details/format.h +++ b/include/spdlog/details/format.h @@ -2638,7 +2638,7 @@ public: typedef BasicMemoryWriter MemoryWriter; typedef BasicMemoryWriter WMemoryWriter; -#ifdef WIN32 +#if defined(WIN32) && defined(SPDLOG_USE_WCHAR) #define TMemoryWriter WMemoryWriter #else #define TMemoryWriter MemoryWriter diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 61e05682..6af4771e 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -149,8 +149,12 @@ constexpr inline unsigned short eol_size() //fopen_s on non windows for writing inline int fopen_s(FILE** fp, const tstring& filename, const tchar* mode) { -#ifdef _WIN32 +#if defined(WIN32) + #if defined(SPDLOG_USE_WCHAR) *fp = _wfsopen((filename.c_str()), mode, _SH_DENYWR); + #else + *fp = _fsopen((filename.c_str()), mode, _SH_DENYWR); + #endif return *fp == nullptr; #else *fp = fopen((filename.c_str()), mode); @@ -160,7 +164,7 @@ inline int fopen_s(FILE** fp, const tstring& filename, const tchar* mode) inline int remove(const tchar* filename) { -#ifdef _WIN32 +#if defined(WIN32) && defined(SPDLOG_USE_WCHAR) return _wremove(filename); #else return std::remove(filename); @@ -169,10 +173,10 @@ inline int remove(const tchar* filename) inline int rename(const tchar* filename1, const tchar* filename2) { -#ifdef _WIN32 +#if defined(WIN32) && defined(SPDLOG_USE_WCHAR) return _wrename(filename1, filename2); #else - return std::remove(filename1); + return std::rename(filename1, filename2); #endif } diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index b651658b..5bb33afd 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -72,3 +72,9 @@ // Note that upon creating a logger the registry is modified by spdlog.. // #define SPDLOG_NO_REGISTRY_MUTEX /////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to disable usage of wchar_t for file names on Windows. +// #define SPDLOG_NO_WCHAR +/////////////////////////////////////////////////////////////////////////////// diff --git a/tests/includes.h b/tests/includes.h index 7cda161d..2c28f7d4 100644 --- a/tests/includes.h +++ b/tests/includes.h @@ -7,6 +7,7 @@ #include #include +#define SPDLOG_NO_WCHAR #include "catch.hpp" #include "../include/spdlog/spdlog.h" #include "../include/spdlog/sinks/null_sink.h"