X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Ftod.c;h=9088fc6046a0f23d223ace6525961403d773145a;hb=fc2ba7b9fae5992dd76f721f283714a6d2ea137d;hp=55933dc844ebc25558c744bc4c810e8f7d870e2e;hpb=c5db348c5e29e93e51389fa0079f829967c5da82;p=exim.git diff --git a/src/src/tod.c b/src/src/tod.c index 55933dc84..9088fc604 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); @@ -73,9 +72,9 @@ switch(type) case tod_zulu: t = gmtime(&now.tv_sec); - (void) sprintf(CS timebuf, "%04d%02d%02d%02d%02d%02dZ", - 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, - t->tm_sec); + (void) sprintf(CS timebuf, "%04u%02u%02u%02u%02u%02uZ", + 1900 + (uint)t->tm_year, 1 + (uint)t->tm_mon, (uint)t->tm_mday, (uint)t->tm_hour, (uint)t->tm_min, + (uint)t->tm_sec); return timebuf; } @@ -85,14 +84,23 @@ 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", - 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); +#ifndef COMPILE_UTILITY + if (LOGGING(millisec)) + sprintf(CS timebuf, "%04u-%02u-%02u %02u:%02u:%02u.%03u", + 1900 + (uint)t->tm_year, 1 + (uint)t->tm_mon, (uint)t->tm_mday, + (uint)t->tm_hour, (uint)t->tm_min, (uint)t->tm_sec, + (uint)(now.tv_usec/1000)); + else +#endif + sprintf(CS timebuf, "%04u-%02u-%02u %02u:%02u:%02u", + 1900 + (uint)t->tm_year, 1 + (uint)t->tm_mon, (uint)t->tm_mday, + (uint)t->tm_hour, (uint)t->tm_min, (uint)t->tm_sec); + break; /* Format used as suffix of log file name when 'log_datestamp' is active. For @@ -101,20 +109,21 @@ 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", - 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min); + sprintf(CS timebuf, "%04u%02u%02u%02u%02u", + 1900 + (uint)t->tm_year, 1 + (uint)t->tm_mon, (uint)t->tm_mday, + (uint)t->tm_hour, (uint)t->tm_min); break; #else case tod_log_datestamp_daily: - off = sprintf(CS timebuf, "%04d%02d%02d", - 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday); + sprintf(CS timebuf, "%04u%02u%02u", + 1900 + (uint)t->tm_year, 1 + (uint)t->tm_mon, (uint)t->tm_mday); break; case tod_log_datestamp_monthly: #ifndef COMPILE_UTILITY - off = sprintf(CS timebuf, "%04d%02d", - 1900 + t->tm_year, 1 + t->tm_mon); + sprintf(CS timebuf, "%04u%02u", + 1900 + (uint)t->tm_year, 1 + (uint)t->tm_mon); #endif break; #endif @@ -141,7 +150,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 { @@ -162,16 +171,16 @@ switch(type) #ifndef COMPILE_UTILITY if (LOGGING(millisec)) (void) sprintf(CS timebuf, - "%04d-%02d-%02d %02d:%02d:%02d.%03d %+03d%02d", - 1900 + local.tm_year, 1 + local.tm_mon, local.tm_mday, - local.tm_hour, local.tm_min, local.tm_sec, (int)(now.tv_usec/1000), + "%04u-%02u-%02u %02u:%02u:%02u.%03u %+03d%02d", + 1900 + (uint)local.tm_year, 1 + (uint)local.tm_mon, (uint)local.tm_mday, + (uint)local.tm_hour, (uint)local.tm_min, (uint)local.tm_sec, (uint)(now.tv_usec/1000), diff_hour, diff_min); else #endif (void) sprintf(CS timebuf, - "%04d-%02d-%02d %02d:%02d:%02d %+03d%02d", - 1900 + local.tm_year, 1 + local.tm_mon, local.tm_mday, - local.tm_hour, local.tm_min, local.tm_sec, + "%04u-%02u-%02u %02u:%02u:%02u %+03d%02d", + 1900 + (uint)local.tm_year, 1 + (uint)local.tm_mon, (uint)local.tm_mday, + (uint)local.tm_hour, (uint)local.tm_min, (uint)local.tm_sec, diff_hour, diff_min); break; @@ -185,7 +194,7 @@ switch(type) case tod_mbx: { int len; - (void) sprintf(CS timebuf, "%02d-", local.tm_mday); + (void) sprintf(CS timebuf, "%02u-", (uint)local.tm_mday); len = Ustrlen(timebuf); len += Ustrftime(timebuf + len, sizeof(timebuf) - len, "%b-%Y %H:%M:%S", &local); @@ -200,7 +209,7 @@ switch(type) default: { int len = Ustrftime(timebuf, sizeof(timebuf), "%a, ", &local); - (void) sprintf(CS timebuf + len, "%02d ", local.tm_mday); + (void) sprintf(CS timebuf + len, "%02u ", (uint)local.tm_mday); len += Ustrlen(timebuf + len); len += Ustrftime(timebuf + len, sizeof(timebuf) - len, "%b %Y %H:%M:%S", &local); @@ -212,13 +221,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; }