diff --git a/simgear/timing/lowleveltime.cxx b/simgear/timing/lowleveltime.cxx index dbd916f9..25acb3e2 100644 --- a/simgear/timing/lowleveltime.cxx +++ b/simgear/timing/lowleveltime.cxx @@ -124,7 +124,7 @@ static int fgcompute_change(fgtz_rule *rule, int year); static struct ttinfo *fgfind_transition (time_t timer); static void fgcompute_tzname_max (size_t chars); static inline int decode (const void *ptr); -void fgtzfile_read (const char *file); +bool fgtzfile_read (const char *file); static void offtime (const time_t *t, long int offset, struct tm *tp); static char *tzstring (const char* string); @@ -327,8 +327,7 @@ static void fgtzset_internal (int always, const char *tz) old_fgtz = tz ? strdup (tz) : NULL; /* Try to read a data file. */ - fgtzfile_read (tz); - if (use_fgtzfile) + if (fgtzfile_read(tz) && use_fgtzfile) return; // The default behaviour of the original tzset_internal (int always, char* tz) // function is to set up a default timezone, in any case file_read() fails @@ -785,7 +784,7 @@ static struct ttinfo * fgfind_transition (time_t timer) /**************************************************************************/ -void fgtzfile_read (const char *file) +bool fgtzfile_read (const char *file) { // static const char default_tzdir[] = TZDIR; size_t num_isstd, num_isgmt; @@ -818,7 +817,7 @@ void fgtzfile_read (const char *file) file = TZDEFAULT; else if (*file == '\0') /* User specified the empty string; use UTC with no leap seconds. */ - return; + return true; else { /* We must not allow to read an arbitrary file in a setuid @@ -866,9 +865,9 @@ void fgtzfile_read (const char *file) #endif if (f == NULL) { - perror( "fgtzfile_read(): " ); +// perror( "fgtzfile_read(): " ); errno = 0; - return; + return false; } if (fread ((void *) &tzhead, sizeof (tzhead), 1, f) != 1) @@ -991,10 +990,11 @@ void fgtzfile_read (const char *file) fgcompute_tzname_max (chars); use_fgtzfile = 1; - return; + return true; lose:; fclose(f); + return false; } /****************************************************************************/ diff --git a/simgear/timing/sg_time.cxx b/simgear/timing/sg_time.cxx index 39c78c85..9e31ef47 100644 --- a/simgear/timing/sg_time.cxx +++ b/simgear/timing/sg_time.cxx @@ -241,10 +241,16 @@ void SGTime::updateLocal( const SGGeod& aLocation, const SGPath& root ) { currGMT = sgTimeGetGMT( gmtime(&cur_time) ); std::string zs = zone.utf8Str(); - aircraftLocalTime = sgTimeGetGMT( (fgLocaltime(&cur_time, zs.c_str())) ); - local_offset = aircraftLocalTime - currGMT; + struct tm *local_time = fgLocaltime(&cur_time, zs.c_str()); + if (local_time) { + aircraftLocalTime = sgTimeGetGMT( local_time ); + local_offset = aircraftLocalTime - currGMT; // cout << "Using " << local_offset << " as local time offset Timezone is " // << zonename << endl; + } + else { + SG_LOG( SG_EVENT, SG_ALERT, "Timezone file not found: " << zs ); + } }