Create fopen wrapper that internally uses wide characters under Windows, issue #261

--HG--
branch : develop
This commit is contained in:
kervala 2016-02-20 17:46:11 +01:00
parent 871093d4ce
commit e69090c457
2 changed files with 15 additions and 0 deletions

View file

@ -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 );

View file

@ -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 )
{