X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/c5db348c5e29e93e51389fa0079f829967c5da82..8768d5483a5894400ae1f70cda1beb44ed9b087c:/src/src/tod.c diff --git a/src/src/tod.c b/src/src/tod.c index 55933dc84..b0d3ac9b0 100644 --- a/src/src/tod.c +++ b/src/src/tod.c @@ -2,7 +2,7 @@ * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2017 */ +/* Copyright (c) University of Cambridge 1995 - 2018 */ /* See the file NOTICE for conditions of use and distribution. */ /* A function for returning the time of day in various formats */ @@ -54,7 +54,6 @@ tod_stamp(int type) { struct timeval now; struct tm * t; -int off = 0; gettimeofday(&now, NULL); @@ -85,14 +84,22 @@ if (type == tod_log) type = log_timezone ? tod_log_zone : tod_log_bare; /* Convert to local time or UTC */ -t = timestamps_utc ? gmtime(&now.tv_sec) : localtime(&now.tv_sec); +t = f.timestamps_utc ? gmtime(&now.tv_sec) : localtime(&now.tv_sec); switch(type) { case tod_log_bare: /* Format used in logging without timezone */ - off = sprintf(CS timebuf, "%04d-%02d-%02d %02d:%02d:%02d", +#ifndef COMPILE_UTILITY + if (LOGGING(millisec)) + sprintf(CS timebuf, "%04d-%02d-%02d %02d:%02d:%02d.%03d", + 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, + t->tm_hour, t->tm_min, t->tm_sec, (int)(now.tv_usec/1000)); + else +#endif + sprintf(CS timebuf, "%04d-%02d-%02d %02d:%02d:%02d", 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + break; /* Format used as suffix of log file name when 'log_datestamp' is active. For @@ -101,19 +108,19 @@ switch(type) #ifdef TESTING_LOG_DATESTAMP case tod_log_datestamp_daily: case tod_log_datestamp_monthly: - off = sprintf(CS timebuf, "%04d%02d%02d%02d%02d", + sprintf(CS timebuf, "%04d%02d%02d%02d%02d", 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min); break; #else case tod_log_datestamp_daily: - off = sprintf(CS timebuf, "%04d%02d%02d", + sprintf(CS timebuf, "%04d%02d%02d", 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday); break; case tod_log_datestamp_monthly: #ifndef COMPILE_UTILITY - off = sprintf(CS timebuf, "%04d%02d", + sprintf(CS timebuf, "%04d%02d", 1900 + t->tm_year, 1 + t->tm_mon); #endif break; @@ -141,7 +148,7 @@ switch(type) struct tm local; memcpy(&local, t, sizeof(struct tm)); - if (timestamps_utc) + if (f.timestamps_utc) diff_hour = diff_min = 0; else { @@ -212,13 +219,6 @@ switch(type) break; } -#ifndef COMPILE_UTILITY -if (LOGGING(millisec) && off > 0) - (void) sprintf(CS timebuf + off, ".%03d", (int)(now.tv_usec/1000)); -#else -off = off; /* Compiler quietening */ -#endif - return timebuf; }