Page 1 of 1

IAR does not have localtime_r?

Posted: Sat Jun 13, 2015 11:32 pm
by russian
I could be wrong but it looks like my IAR time.h does not contain localtime_r?

In 2.6 I've ended up doing

Code: Select all

Index: os/various/chrtclib.c
===================================================================
--- os/various/chrtclib.c
+++ os/various/chrtclib.c
@@ -215,7 +215,12 @@
 #endif
   struct tm timp;
 
+#if defined __GNUC__
   localtime_r(&tv_sec, &timp);
+#else
+  struct tm *t = localtime(&tv_sec);
+  memcpy(&timp, t, sizeof(struct tm));
+#endif
   stm32_rtc_tm2bcd(&timp, &timespec);
   rtcSetTime(rtcp, &timespec);
 }
@@ -257,7 +262,13 @@
   RTCTime timespec = {0};
 
   rtcGetTime(rtcp, &timespec);
+#if defined __GNUC__
   localtime_r((time_t *)&(timespec.tv_sec), timp);
+#else
+  struct tm *t = localtime((time_t *)&(timespec.tv_sec));
+  memcpy(&timp, t, sizeof(struct tm));
+#endif
+
 }
 
 /**


I know it's different in 3.0, but it does use localtime_r also.

But it could be that I am missing something.

Re: IAR does not have localtime_r?

Posted: Sun Jun 14, 2015 8:04 am
by Giovanni
Hi,

I think localtime_r is specific of newlib, I will apply the patch.

Giovanni