From 99a5e6392eefe95eb6584975b90b04fcd287537e Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 14 May 2007 23:48:55 +0000 Subject: [PATCH] Attempt to fix bsmtp editing on OSes without %z editing. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4788 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/tools/bsmtp.c | 63 ++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/bacula/src/tools/bsmtp.c b/bacula/src/tools/bsmtp.c index 3bd13f0fef..2701f7ba4e 100644 --- a/bacula/src/tools/bsmtp.c +++ b/bacula/src/tools/bsmtp.c @@ -145,6 +145,43 @@ _("\n" exit(1); } +static void get_date_string(char *buf, int buf_len) +{ + time_t now = time(NULL); + struct tm tm; + char tzbuf[MAXSTRING]; + + /* Add RFC822 date */ + (void)localtime_r(&now, &tm); + +#if defined(HAVE_WIN32) +#if defined(HAVE_MINGW) +__MINGW_IMPORT long _dstbias; +#endif + long tzoffset = 0; + + _tzset(); + + tzoffset = _timezone; + tzoffset += _dstbias; + tzoffset /= 60; + + size_t length = strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S", &tm); + sprintf(&buf[length], " %+2.2ld%2.2u", -tzoffset / 60, abs(tzoffset) % 60); +#else + strftime(buf, buf_len, "%a, %d %b %Y %H:%M:%S", &tm); + tzset(); + timezone /= 60; /* timezone offset in mins */ + if (tm.tm_isdst == 1) { + timezone -= 60; /* adjust for daylight savings */ + } + sprintf(tzbuf, " %+2.2ld%2.2u", -timezone / 60, abs(timezone) % 60); + strcat(buf, tzbuf); /* add +0100 */ + strftime(tzbuf, sizeof(tzbuf), " (%Z)", &tm); + strcat(buf, tzbuf); /* add (CEST) */ +#endif +} + /********************************************************************* * @@ -164,8 +201,6 @@ int main (int argc, char *argv[]) struct passwd *pwd; #endif char *cp, *p; - time_t now = time(NULL); - struct tm tm; setlocale(LC_ALL, "en_US"); bindtextdomain("bacula", LOCALEDIR); @@ -458,29 +493,7 @@ hp: Dmsg0(10, "Content-Type: text/plain; charset=UTF-8\r\n"); } - /* Add RFC822 date */ - (void)localtime_r(&now, &tm); -#if defined(HAVE_WIN32) -#if defined(HAVE_MINGW) -__MINGW_IMPORT long _dstbias; -#endif - long tzoffset = 0; - - _tzset(); - - tzoffset = _timezone; - tzoffset += _dstbias; - tzoffset /= 60; - - size_t length = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S", &tm); - sprintf(&buf[length], " %+2.2ld%2.2u", -tzoffset / 60, abs(tzoffset) % 60); -#else -#ifdef HAVE_SUN_OS - strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S (%Z)", &tm); -#else - strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S %z (%Z)", &tm); -#endif -#endif + get_date_string(buf, sizeof(buf)); fprintf(sfp, "Date: %s\r\n", buf); Dmsg1(10, "Date: %s\r\n", buf); -- 2.39.5