I have a program that was originally written for Linux, but I now have a requirement to get it running on Solaris 10.
Part of this program uses the timegm function to convert a struct tm
into a time_t
epoch seconds value. The input time is referenced to UTC.
Trying to compile this program on Solaris, it fails because timegm
cannot be found. After some googling I realized that this function has been removed from Solaris a long time ago (and even the Linux manpage recommends against using it, because it isn't standardized).
However I have so far not been able to find an alternative function, that takes a struct tm
referenced to UTC and converts to epoch time. Most references I found on the net recommend using mktime, however that function interprets the inputs with reference to the system local time zone.
Note that I do not wish to use tzset
to force the timezone to UTC, as that would have other side effects on the program.
So my question is: how can I convert a struct tm
broken down time value, expressed with respect to UTC, into an epoch time, in the absence of timegm
?
The program is written in C++ so I'm not limited to C solutions, although I would prefer not to embark on a wholesale rewrite to use some additional time library.