title: localtime() is off by about 460,000 years on RTL8710
body: <p>I'm using an RTL8710 (running <a href="https://github.com/lupyuen/rustl8710" rel="nofollow noreferrer">rustl8710</a>, but that's irrelevant as far as this question goes, since all code I'm talking about is C code). The RTL8710 has proprietary libraries for some parts of the system, including <code>localtime</code>.</p>
  
  <p>However, <code>localtime</code> seems to be off by about 460,000 years when using it like this (taken from <a href="https://github.com/lupyuen/rustl8710/blob/master/component/common/network/sntp/sntp.c#L182" rel="nofollow noreferrer">the included NTP implementation</a>):</p>
  
  <pre><code>long current_sec = 1543067026;
  struct tm current_tm = *(localtime(&amp;current_sec));
  </code></pre>
  
  <p>This returns the following struct:</p>
  
  <pre><code>{tm_sec = 51, 
   tm_min = 36, 
   tm_hour = 15, 
   tm_mday = 25, 
   tm_mon = 8, 
   tm_year = -458682, 
   tm_wday = 2, 
   tm_yday = 267, 
   tm_isdst = -1515870811}
  </code></pre>
  
  <p>Obviously that's incorrect, it should be something close to 24 Nov 2018 13:52:04 GMT. It's not random though, because the time always seems to differ by around 2 hours and some minutes.</p>
  
  <p>The only other noteworthy thing here is that the code uses the default system headers <code>time.h</code> and <code>string.h</code> (which would be from Ubuntu 18.10, 64bit in my case).</p>
  
  <p>I have no idea what stdlib library RealTek is really using, but judging by debugging info (<code>newlib/libc/time/lcltime.c</code>), I'd guess that it's a (modified?) version of newlib.</p>