From: Kern Sibbald Date: Sat, 25 Aug 2007 13:28:54 +0000 (+0000) Subject: kes Integrate more portable zone offset code into bsmtp.c X-Git-Tag: Release-7.0.0~5788 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8485232d39f085a09acdd645b12338e1457b5734;p=bacula%2Fbacula kes Integrate more portable zone offset code into bsmtp.c Submitted by Attila Fülöp. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5405 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/AUTHORS b/bacula/AUTHORS index 93575d2d9e..582c2538e6 100644 --- a/bacula/AUTHORS +++ b/bacula/AUTHORS @@ -17,6 +17,7 @@ Alexandre Baron Andreas Piesk Andrew Ford Arno Lehmann +Attila Fülöp Bernd Frick Bill Moran Carlos A. Molina G diff --git a/bacula/src/tools/bsmtp.c b/bacula/src/tools/bsmtp.c index 03b5f5c3a7..d58d032b3c 100644 --- a/bacula/src/tools/bsmtp.c +++ b/bacula/src/tools/bsmtp.c @@ -171,6 +171,37 @@ _("\n" exit(1); } +/* + * Return the offset west from localtime to UTC in minutes + * Same as timezone.tz_minuteswest + * Unix tz_offset coded by: Attila Fülöp + */ + +static long tz_offset(time_t lnow, struct tm &tm) +{ +#if defined(HAVE_WIN32) +#if defined(HAVE_MINGW) +__MINGW_IMPORT long _dstbias; +#endif + + /* Win32 code */ + long offset; + _tzset(); + offset = _timezone; + offset += _dstbias; + return offset /= 60; +#else + + /* Unix/Linux code */ + struct tm tm_utc; + time_t now = lnow; + + (void)gmtime_r(&now, &tm_utc); + tm_utc.tm_isdst = tm.tm_isdst; + return (long)difftime(mktime(&tm_utc), now) / 60; +#endif +} + static void get_date_string(char *buf, int buf_len) { time_t now = time(NULL); @@ -181,21 +212,7 @@ static void get_date_string(char *buf, int buf_len) /* Add RFC822 date */ (void)localtime_r(&now, &tm); -#if defined(HAVE_WIN32) -#if defined(HAVE_MINGW) -__MINGW_IMPORT long _dstbias; -#endif - _tzset(); - my_timezone = _timezone; - my_timezone += _dstbias; - my_timezone /= 60; - -#else - struct timeval tv; - struct timezone tz; - gettimeofday(&tv, &tz); - my_timezone = tz.tz_minuteswest; /* timezone offset in mins */ -#endif + my_timezone = tz_offset(now, tm); strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S", &tm); sprintf(tzbuf, " %+2.2ld%2.2u", -my_timezone / 60, abs(my_timezone) % 60); strcat(buf, tzbuf); /* add +0100 */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 71fcfa9bd5..e46ca39912 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,9 @@ Technical notes on version 2.3 General: +25Aug07 +kes Integrate more portable zone offset code into bsmtp.c + Submitted by Attila Fülöp. 24Aug07 kes Fix bad SD->FD return status reported by (James Harper)