daokoder / dao-modules

Dao Standard Modules
http://daovm.net
12 stars 5 forks source link

timegm() is not portable #63

Closed dumblob closed 9 years ago

dumblob commented 9 years ago

In time/dao_time.c the DaoMkTimeUtc() is implemented on UNIX using timegm(), but it's a GNU extension (i.e. not POSIX) and also it's not recommended to use it - I'd use the solution described in Notes on the linked manual page.

Night-walker commented 9 years ago

I'd rather avoid that solution you mentioned: messing with environment variables is slow and may accidentally affect other threads (non-Dao-based) which rely on C's time functions.

dumblob commented 9 years ago

This one is fast, portable and we should use it (it's Public domain, which is forbidden in Europe, but you can take over the authorship, so then it's not an issue in Europe any more - Red Hat does it exactly this way with Public domain :wink:): http://www.catb.org/esr/time-programming/#_mktime_3_timelocal_3_timegm_3 .

dumblob commented 9 years ago

Portability (and especially regarding time) should be much more important for us then speed (at least for the time being).

dumblob commented 9 years ago

Or alternatively similar implementation http://stackoverflow.com/questions/16647819/timegm-cross-platform .

Night-walker commented 9 years ago

OK, I added the TZ-way for platforms where timegm() may be unavailable.

dumblob commented 9 years ago

Ok, good. As it's impossible to have a really portable solution here (because as it's said in several other implementations of timegm(), it's impossible to construct a correct algorithm using only POSIX-compliant interface), the TZ-solution is acceptable.