SGFile uses wide-string APIs on Windows.

This commit is contained in:
James Turner
2017-02-07 16:15:14 +00:00
parent c3f48c7261
commit d9f4d7373f
+14 -3
View File
@@ -69,16 +69,27 @@ SGFile::~SGFile() {
bool SGFile::open( const SGProtocolDir d ) { bool SGFile::open( const SGProtocolDir d ) {
set_dir( d ); set_dir( d );
std::string n = file_name.local8BitStr(); #if defined(SG_WINDOWS)
std::wstring n = file_name.wstr();
#else
std::string n = file_name.utf8Str();
#endif
if ( get_dir() == SG_IO_OUT ) { if ( get_dir() == SG_IO_OUT ) {
#ifdef _WIN32 #if defined(SG_WINDOWS)
int mode = _S_IREAD | _S_IWRITE; int mode = _S_IREAD | _S_IWRITE;
fp = ::_wopen(n.c_str(), O_WRONLY | O_CREAT | O_TRUNC | extraoflags, mode);
#else #else
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
#endif
fp = ::open( n.c_str(), O_WRONLY | O_CREAT | O_TRUNC | extraoflags, mode ); fp = ::open( n.c_str(), O_WRONLY | O_CREAT | O_TRUNC | extraoflags, mode );
#endif
} else if ( get_dir() == SG_IO_IN ) { } else if ( get_dir() == SG_IO_IN ) {
#if defined(SG_WINDOWS)
fp = ::_wopen( n.c_str(), O_RDONLY | extraoflags );
#else
fp = ::open( n.c_str(), O_RDONLY | extraoflags ); fp = ::open( n.c_str(), O_RDONLY | extraoflags );
#endif
} else { } else {
SG_LOG( SG_IO, SG_ALERT, SG_LOG( SG_IO, SG_ALERT,
"Error: bidirection mode not available for files." ); "Error: bidirection mode not available for files." );