From b258bc598e4cc5239b3a2b25f30dec8d28bb5e05 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 13 Mar 2020 16:48:12 +0000 Subject: [PATCH] Load time-zones from UTF-8 paths correctly Use _wfopen on Windows, after converting UTF-8 paths to wchar --- simgear/timing/lowleveltime.cxx | 8 +++++++- simgear/timing/sg_time.cxx | 4 ++-- simgear/timing/timezone.cxx | 8 +++++++- 3 files changed, 16 insertions(+), 4 deletions(-) mode change 100644 => 100755 simgear/timing/timezone.cxx diff --git a/simgear/timing/lowleveltime.cxx b/simgear/timing/lowleveltime.cxx index ae994f31..903877c4 100644 --- a/simgear/timing/lowleveltime.cxx +++ b/simgear/timing/lowleveltime.cxx @@ -42,6 +42,7 @@ #include #include +#include #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(): " ); diff --git a/simgear/timing/sg_time.cxx b/simgear/timing/sg_time.cxx index dc8b6ac0..bbabd1a4 100644 --- a/simgear/timing/sg_time.cxx +++ b/simgear/timing/sg_time.cxx @@ -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 " diff --git a/simgear/timing/timezone.cxx b/simgear/timing/timezone.cxx old mode 100644 new mode 100755 index 4fa6746c..b1fc6344 --- a/simgear/timing/timezone.cxx +++ b/simgear/timing/timezone.cxx @@ -36,6 +36,7 @@ #include #include +#include #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 + '\'');