From d9f4d7373f36c0496fc2ed5efd2ab946dfbd1420 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 26 Jan 2017 20:14:11 +0000 Subject: [PATCH] SGFile uses wide-string APIs on Windows. --- simgear/io/sg_file.cxx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/simgear/io/sg_file.cxx b/simgear/io/sg_file.cxx index 1a23fbfa..4b25a952 100644 --- a/simgear/io/sg_file.cxx +++ b/simgear/io/sg_file.cxx @@ -69,16 +69,27 @@ SGFile::~SGFile() { bool SGFile::open( const SGProtocolDir 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 ) { -#ifdef _WIN32 +#if defined(SG_WINDOWS) int mode = _S_IREAD | _S_IWRITE; + fp = ::_wopen(n.c_str(), O_WRONLY | O_CREAT | O_TRUNC | extraoflags, mode); #else 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 ); +#endif } 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 ); +#endif } else { SG_LOG( SG_IO, SG_ALERT, "Error: bidirection mode not available for files." ); @@ -145,7 +156,7 @@ int SGFile::readline( char *buf, int length ) { result = i; } lseek( fp, pos + result, SEEK_SET ); - + // just in case ... buf[ result ] = '\0';