lib/iec_std_lib.h
changeset 709 bca119630cf6
parent 707 e666763ac743
child 711 8a1ba3db05b2
equal deleted inserted replaced
708:6cc8255ecfe4 709:bca119630cf6
   222   ts.tv_nsec = (long int)((total_sec - ts.tv_sec)*1e9);
   222   ts.tv_nsec = (long int)((total_sec - ts.tv_sec)*1e9);
   223 
   223 
   224   return ts;
   224   return ts;
   225 }
   225 }
   226 
   226 
       
   227 #ifdef __MINGW32__
       
   228 #define TIMEGM mktime
       
   229 #else
       
   230 #define TIMEGM timegm
       
   231 #endif
       
   232 
   227 static inline IEC_TIMESPEC __date_to_timespec(int day, int month, int year) {
   233 static inline IEC_TIMESPEC __date_to_timespec(int day, int month, int year) {
   228   IEC_TIMESPEC ts;
   234   IEC_TIMESPEC ts;
   229   struct tm broken_down_time;
   235   struct tm broken_down_time;
   230   time_t epoch_seconds;
   236   time_t epoch_seconds;
   231 
   237 
   235   broken_down_time.tm_mday = day;  /* day of month, from 1 to 31 */
   241   broken_down_time.tm_mday = day;  /* day of month, from 1 to 31 */
   236   broken_down_time.tm_mon = month - 1;   /* month since January, in the range 0 to 11 */
   242   broken_down_time.tm_mon = month - 1;   /* month since January, in the range 0 to 11 */
   237   broken_down_time.tm_year = year - 1900;  /* number of years since 1900 */
   243   broken_down_time.tm_year = year - 1900;  /* number of years since 1900 */
   238   broken_down_time.tm_isdst = -1; /* disable daylight savings time */
   244   broken_down_time.tm_isdst = -1; /* disable daylight savings time */
   239   
   245   
   240   epoch_seconds = timegm(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */
   246   epoch_seconds = TIMEGM(&broken_down_time); /* determine number of seconds since the epoch, i.e. Jan 1st 1970 */
   241 
   247 
   242   if ((time_t)(-1) == epoch_seconds)
   248   if ((time_t)(-1) == epoch_seconds)
   243     __iec_error();
   249     __iec_error();
   244 
   250 
   245   ts.tv_sec = epoch_seconds;
   251   ts.tv_sec = epoch_seconds;