mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 03:19:02 +08:00
Add the SPDLOG_USE_WCHAR tweak to enable support for Unicode names on Windows. Refs #111
This commit is contained in:
@@ -137,24 +137,49 @@ constexpr inline unsigned short eol_size()
|
||||
#endif
|
||||
|
||||
//fopen_s on non windows for writing
|
||||
inline int fopen_s(FILE** fp, const std::string& filename, const char* mode)
|
||||
inline int fopen_s(FILE** fp, const filename_str_t& filename, const filename_char_t* mode)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#ifdef 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);
|
||||
return *fp == nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int remove(const filename_char_t* filename)
|
||||
{
|
||||
#if defined(_WIN32) && defined(SPDLOG_USE_WCHAR)
|
||||
return _wremove(filename);
|
||||
#else
|
||||
return std::remove(filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int rename(const filename_char_t* filename1, const filename_char_t* filename2)
|
||||
{
|
||||
#if defined(_WIN32) && defined(SPDLOG_USE_WCHAR)
|
||||
return _wrename(filename1, filename2);
|
||||
#else
|
||||
return std::rename(filename1, filename2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//Return if file exists
|
||||
inline bool file_exists(const std::string& filename)
|
||||
inline bool file_exists(const filename_str_t& filename)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#ifdef SPDLOG_USE_WCHAR
|
||||
auto attribs = GetFileAttributesW(filename.c_str());
|
||||
#else
|
||||
auto attribs = GetFileAttributesA(filename.c_str());
|
||||
#endif
|
||||
return (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY));
|
||||
#elif __linux__
|
||||
struct stat buffer;
|
||||
@@ -169,7 +194,6 @@ inline bool file_exists(const std::string& filename)
|
||||
return false;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//Return utc offset in minutes or throw spdlog_ex on failure
|
||||
|
Reference in New Issue
Block a user