@@ -59,6 +59,28 @@ static int gExtensionPrevState = PARSING_NONE;
5959static int gExtensionLevelDepth = 0 ;
6060static bool gExtensionDoubleOpen = false ;
6161
62+ static void SYS_setenv (const char *name, const char *value)
63+ {
64+ #ifdef WIN32
65+ char str[128 ];
66+ sprintf (str, " %s=%s" , name, value);
67+ putenv (str);
68+ #else
69+ setenv (name, value, 1 );
70+ #endif
71+ }
72+
73+ static void SYS_unsetenv (const char *name)
74+ {
75+ #ifdef WIN32
76+ char str[128 ];
77+ sprintf (str, " %s=" , name);
78+ putenv (str);
79+ #else
80+ unsetenv (name);
81+ #endif
82+ }
83+
6284static int getChar (void * ptr)
6385{
6486 return ((ifstream*)((T_uXml*)ptr)->fp )->get ();
@@ -74,7 +96,7 @@ static time_t strToTime(const string str)
7496 timeinfo.tm_min = atoi (str.substr (14 , 2 ).c_str ());
7597 timeinfo.tm_sec = atoi (str.substr (17 , 2 ).c_str ());
7698 timeinfo.tm_isdst = 0 ;
77- return mktime (&timeinfo) - timezone ;
99+ return mktime (&timeinfo);
78100}
79101
80102static int strToMilliseconds (const string str)
@@ -721,6 +743,8 @@ static void closeTag(void* pXml, char* pTag)
721743
722744GPX_model::retCode_e GPXFile::load (ifstream* fp, GPX_model* gpxm, bool overwriteMetadata)
723745{
746+ int ret;
747+ char *tz;
724748 T_uXml uXML;
725749
726750 UXML_init (&uXML);
@@ -739,9 +763,23 @@ GPX_model::retCode_e GPXFile::load(ifstream* fp, GPX_model* gpxm, bool overwrite
739763 gOverwriteMetadata = overwriteMetadata;
740764 gExtensionVector = NULL ;
741765
742- if (UXML_parseFile (&uXML) != 0 )
743- return GPX_model::GPXM_ERR_FAILED;
766+ // set timezone temporary to UTC
767+ tz = getenv (" TZ" );
768+ SYS_setenv (" TZ" , " UTC" );
769+ tzset ();
770+
771+ // parse file
772+ ret = UXML_parseFile (&uXML);
744773
774+ // change back timezone
775+ if (tz)
776+ SYS_setenv (" TZ" , tz);
777+ else
778+ SYS_unsetenv (" TZ" );
779+ tzset ();
780+
781+ if (ret != 0 )
782+ return GPX_model::GPXM_ERR_FAILED;
745783 return GPX_model::GPXM_OK;
746784}
747785
@@ -1004,7 +1042,7 @@ GPX_model::retCode_e GPXFile::save(ofstream* fp, const GPX_model* gpxm)
10041042 writeLink (fp, 2 , &*link);
10051043 writeLineIndent (fp, 2 );
10061044 writeStr (fp, " <number>" , false );
1007- sprintf (gBuffer , " %d " , trk->metadata .number );
1045+ sprintf (gBuffer , " %zu " , trk->metadata .number );
10081046 writeStr (fp, gBuffer , false );
10091047 writeStr (fp, " </number>" );
10101048 if (!trk->metadata .type .empty ())
0 commit comments