diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 3b5465eaa..23b827a0b 100644 --- a/code/nel/include/nel/misc/common.h +++ b/code/nel/include/nel/misc/common.h @@ -282,6 +282,13 @@ inline sint nlstricmp(const std::string &lhs, const std::string &rhs) { return s inline sint nlstricmp(const std::string &lhs, const char *rhs) { return stricmp(lhs.c_str(),rhs); } inline sint nlstricmp(const char *lhs, const std::string &rhs) { return stricmp(lhs,rhs.c_str()); } +// macros helper to convert UTF-8 std::string and wchar_t* +#define wideToUtf8(str) (ucstring((ucchar*)str).toUtf8()) +#define utf8ToWide(str) ((wchar_t*)ucstring::makeFromUtf8(str).c_str()) + +// wrapper for fopen to be able to open files with an UTF-8 filename +FILE* nlfopen(const std::string &filename, const std::string &mode); + /** Signed 64 bit fseek. Same interface as fseek */ int nlfseek64( FILE *stream, sint64 offset, int origin ); diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index decd52dbf..c1a824b23 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -1099,6 +1099,14 @@ void displayDwordBits( uint32 b, uint nbits, sint beginpos, bool displayBegin, N } } +FILE* nlfopen(const std::string &filename, const std::string &mode) +{ +#ifdef NL_OS_WINDOWS + return _wfopen(utf8ToWide(filename), utf8ToWide(mode)); +#else + return fopen(filename.c_str(), mode.c_str()); +#endif +} int nlfseek64( FILE *stream, sint64 offset, int origin ) {