From 577a3be97af1ce381de2194f5860be58b279f388 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 6 Sep 2017 18:19:57 +0200 Subject: [PATCH] Improve code clarity in get_gmtoff(). --- rinetd.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/rinetd.c b/rinetd.c index 59bdbbf..d0381c5 100644 --- a/rinetd.c +++ b/rinetd.c @@ -985,19 +985,17 @@ static int readArgs (int argc, char **argv, RinetdOptions *options) /* get_gmtoff was borrowed from Apache. Thanks folks. */ -static struct tm *get_gmtoff(int *tz) { +static struct tm *get_gmtoff(int *tz) +{ time_t tt = time(NULL); - struct tm gmt; - struct tm *t; - int days, hours, minutes; /* Assume we are never more than 24 hours away. */ - gmt = *gmtime(&tt); /* remember gmtime/localtime return ptr to static */ - t = localtime(&tt); /* buffer... so be careful */ - days = t->tm_yday - gmt.tm_yday; - hours = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + struct tm gmt = *gmtime(&tt); /* remember gmtime/localtime return ptr to static */ + struct tm *t = localtime(&tt); /* buffer... so be careful */ + int days = t->tm_yday - gmt.tm_yday; + int hours = ((days < -1 ? 24 : 1 < days ? -24 : days * 24) + t->tm_hour - gmt.tm_hour); - minutes = hours * 60 + t->tm_min - gmt.tm_min; + int minutes = hours * 60 + t->tm_min - gmt.tm_min; *tz = minutes; return t; }