Load time-zones from UTF-8 paths correctly

Use _wfopen on Windows, after converting UTF-8 paths to wchar
This commit is contained in:
James Turner
2020-03-13 16:48:12 +00:00
parent f25c0c60a8
commit b258bc598e
3 changed files with 16 additions and 4 deletions

View File

@@ -42,6 +42,7 @@
#include <limits.h>
#include <simgear/structure/exception.hxx>
#include <simgear/misc/strutils.hxx>
#include "lowleveltime.h"
@@ -857,7 +858,12 @@ void fgtzfile_read (const char *file)
// file = _new;
// }
f = fopen (file, "rb");
#if defined(SG_WINDOWS)
const std::wstring wfile = simgear::strutils::convertUtf8ToWString(file);
f = _wfopen(wfile.c_str(), L"rb");
#else
f = fopen(file, "rb");
#endif
if (f == NULL) {
perror( "fgtzfile_read(): " );

View File

@@ -86,7 +86,7 @@ void SGTime::init( const SGGeod& location, const SGPath& root, time_t init_time
SGPath zone( root );
zone.append( "zone.tab" );
SG_LOG( SG_EVENT, SG_INFO, "Reading timezone info from: " << zone );
std::string zs = zone.local8BitStr();
std::string zs = zone.utf8Str();
static_tzContainer.reset(new SGTimeZoneContainer( zs.c_str() ));
}
@@ -243,7 +243,7 @@ void SGTime::updateLocal( const SGGeod& aLocation, const SGPath& root ) {
}
currGMT = sgTimeGetGMT( gmtime(&cur_time) );
std::string zs = zone.local8BitStr();
std::string zs = zone.utf8Str();
aircraftLocalTime = sgTimeGetGMT( (fgLocaltime(&cur_time, zs.c_str())) );
local_offset = aircraftLocalTime - currGMT;
// cout << "Using " << local_offset << " as local time offset Timezone is "

8
simgear/timing/timezone.cxx Normal file → Executable file
View File

@@ -36,6 +36,7 @@
#include <cstdlib>
#include <simgear/structure/exception.hxx>
#include <simgear/misc/strutils.hxx>
#include "timezone.h"
@@ -134,7 +135,12 @@ SGTimeZone::SGTimeZone(const SGTimeZone& other)
SGTimeZoneContainer::SGTimeZoneContainer(const char *filename)
{
char buffer[256];
FILE* infile = fopen(filename, "rb");
#if defined(SG_WINDOWS)
const std::wstring wfile = simgear::strutils::convertUtf8ToWString(filename);
FILE* infile = _wfopen(wfile.c_str(), L"rb");
#else
FILE* infile = fopen(filename, "rb");
#endif
if (!(infile)) {
std::string e = "Unable to open time zone file '";
throw sg_exception(e + filename + '\'');