Skip to content

Commit

Permalink
Disable usage of wchar_t in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-martynovich committed Jul 21, 2015
1 parent 5508607 commit 787aa46
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
6 changes: 5 additions & 1 deletion include/spdlog/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/details/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2638,7 +2638,7 @@ class BasicMemoryWriter : public BasicWriter<Char> {
typedef BasicMemoryWriter<char> MemoryWriter;
typedef BasicMemoryWriter<wchar_t> WMemoryWriter;

#ifdef WIN32
#if defined(WIN32) && defined(SPDLOG_USE_WCHAR)
#define TMemoryWriter WMemoryWriter
#else
#define TMemoryWriter MemoryWriter
Expand Down
12 changes: 8 additions & 4 deletions include/spdlog/details/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions include/spdlog/tweakme.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
///////////////////////////////////////////////////////////////////////////////
1 change: 1 addition & 0 deletions tests/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <chrono>
#include <exception>

#define SPDLOG_NO_WCHAR
#include "catch.hpp"
#include "../include/spdlog/spdlog.h"
#include "../include/spdlog/sinks/null_sink.h"

0 comments on commit 787aa46

Please sign in to comment.