The code below demonstrates the problem, if you have confgured a different timezone for your PSP than UTC. "localtime" returns UTC instead of the local time.
Shine wrote:This doesn't help, because I'm not living in the EST5 timezone :-)
It was a proof of concept :P Thanks for the init code.
I just committed changes so that the timezone is initialized on startup. As a side-effect, newlib now requires linking with -lpsputility. This is handled automatically if you use build.mak or SDL.
I'm going to remove the dependencies in newlib libc on tzset(), setenv(), and libpsputility.a because they include a ton of bloated code in typical newlib fashion. I'm also not too fond of depending on -lpsputility for just one function, and then needing to specify -lpsputility for autoconf programs, etc.
To do this, I'm going to replace tzset() with a version that calls jimparis' original tz init code the first time it's called. This will mean that any programs that need the timezone set must explicitly call tzset(). Note that newlib setenv() will call tzset() when you pass "TZ", so it's best to just call tzset() directly.
Done. Also, I was wrong about setenv(), it only calls tzset() if TZ was previously set. Anyway the code should be correct. It will also make sure TZ isn't set before initializing it from the PSP settings, so that programs can override TZ if necessary.
As an aside, removing this code and replacing printf() and its cousins with a smaller version (an earlier change), now makes newlib libc only slightly larger than PSPSDK's libc for most programs. The remaining differences in size can probably be attributed to the thread-safe code in newlib (which we don't use currently). Just wanted to point out that it's now feasible for *everyone* to use newlib :).