Skip to content

Commit

Permalink
degrib: use gmtime_r() or gmtime_s() when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 11, 2024
1 parent 5f1ba4c commit 22894dd
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions frmts/grib/degrib/degrib/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ sChar Clock_GetTimeZone ()
{
struct tm l_time;
time_t ansTime;
struct tm *gmTime;
static int timeZone = 9999;

if (timeZone == 9999) {
Expand All @@ -721,10 +720,21 @@ sChar Clock_GetTimeZone ()
l_time.tm_year = 70;
l_time.tm_mday = 2;
ansTime = mktime (&l_time);
gmTime = gmtime (&ansTime);
timeZone = gmTime->tm_hour;
if (gmTime->tm_mday != 2) {
timeZone -= 24;
#if HAVE_GMTIME_R
struct tm gmTime;
const struct tm *gmTimePtr = gmtime_r(&ansTime, &gmTime);
#elif defined(_WIN32)
struct tm gmTime;
const struct tm *gmTimePtr = gmtime_s(&gmTime, &ansTime) == 0 ? &gmTime : NULL;
#else
const struct tm *gmTimePtr = gmtime (&ansTime);
#endif
if (gmTimePtr)
{
timeZone = gmTimePtr->tm_hour;
if (gmTimePtr->tm_mday != 2) {
timeZone -= 24;
}
}
}
return timeZone;
Expand Down

0 comments on commit 22894dd

Please sign in to comment.