diff options
author | Freddy DISSAUX <dsx@pouet.bsdsx.fr> | 2016-05-06 10:19:27 +0200 |
---|---|---|
committer | Freddy DISSAUX <dsx@pouet.bsdsx.fr> | 2016-05-06 10:19:27 +0200 |
commit | 356fbea1c0545459ddf61a1898cf28081cf6ac5e (patch) | |
tree | 4c4abd4f2318107c45bbb1ee06fee2c24fd1e3ea /smtpd/to.c | |
parent | Revert "solaris don't have tm_gmtoff/tm_zone" (diff) | |
download | OpenSMTPD-356fbea1c0545459ddf61a1898cf28081cf6ac5e.tar.xz OpenSMTPD-356fbea1c0545459ddf61a1898cf28081cf6ac5e.zip |
Some Os (as Solaris) don't have member tm_gmtoff in struct tm
Diffstat (limited to 'smtpd/to.c')
-rw-r--r-- | smtpd/to.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -200,21 +200,31 @@ time_to_text(time_t when) char *day[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; char *month[] = {"Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec"}; + char *tz; + long offset; lt = localtime(&when); if (lt == NULL || when == 0) fatalx("time_to_text: localtime"); +#if HAVE_STRUCT_TM_TM_GMTOFF + offset = lt->tm_gmtoff; + tz = lt->tm_zone; +#elif defined HAVE_DECL_ALTZONE && defined HAVE_DECL_TIMEZONE + offset = lt->tm_isdst > 0 ? altzone : timezone; + tz = lt->tm_isdst > 0 ? tzname[1] : tzname[0]; +#endif + /* We do not use strftime because it is subject to locale substitution*/ if (!bsnprintf(buf, sizeof(buf), "%s, %d %s %d %02d:%02d:%02d %c%02d%02d (%s)", day[lt->tm_wday], lt->tm_mday, month[lt->tm_mon], lt->tm_year + 1900, lt->tm_hour, lt->tm_min, lt->tm_sec, - lt->tm_gmtoff >= 0 ? '+' : '-', - abs((int)lt->tm_gmtoff / 3600), - abs((int)lt->tm_gmtoff % 3600) / 60, - lt->tm_zone)) + offset >= 0 ? '+' : '-', + abs((int)offset / 3600), + abs((int)offset % 3600) / 60, + tz)) fatalx("time_to_text: bsnprintf"); return buf; |