diff options
author | TingPing <tngpng@gmail.com> | 2013-07-01 18:51:51 -0700 |
---|---|---|
committer | TingPing <tngpng@gmail.com> | 2013-07-01 18:51:51 -0700 |
commit | 340811da6ed28f6ea0e30f27ce041cfc0a263bef (patch) | |
tree | 1f4128ea7ef6260de4232648a7b8d965a3883ced /src/common/proto-irc.c | |
parent | 82277a80eae4e300935a6e90f053a5b22fac5850 (diff) | |
parent | 4b40597c76063e0d97c6e0b6295c72caf3dc2d07 (diff) |
Merge pull request #665 from orium/freebsd-fixes
Freebsd fixes
Diffstat (limited to 'src/common/proto-irc.c')
-rw-r--r-- | src/common/proto-irc.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/common/proto-irc.c b/src/common/proto-irc.c index 7742c064..29102afc 100644 --- a/src/common/proto-irc.c +++ b/src/common/proto-irc.c @@ -1326,6 +1326,34 @@ process_named_servermsg (session *sess, char *buf, char *rawname, char *word_eol rawname, NULL, 0, tags_data->timestamp); } +/* Returns the timezone offset. This should be the same as the variable + * "timezone" in time.h, but *BSD doesn't have it. + */ +static int +get_timezone(void) +{ + struct tm tm_utc, tm_local; + time_t t, time_utc, time_local; + + time (&t); + + /* gmtime() and localtime() are thread-safe on windows. + * on other systems we should use {gmtime,localtime}_r(). + */ +#if WIN32 + tm_utc = *gmtime (&t); + tm_local = *localtime (&t); +#else + gmtime_r (&t, &tm_utc); + localtime_r (&t, &tm_local); +#endif + + time_utc = mktime (&tm_utc); + time_local = mktime (&tm_local); + + return time_utc - time_local; +} + /* Handle time-server tags. * * Sets tags_data->timestamp to the correct time (in unix time). @@ -1370,7 +1398,7 @@ handle_message_tag_time (const char *time, message_tags_data *tags_data) } /* get rid of the local time (mktime() receives a local calendar time) */ - tags_data->timestamp -= timezone; + tags_data->timestamp -= get_timezone(); } else { |