X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Ftod.c;h=9aa845c822b706596a3653ecd0450de460f7213a;hb=9815773952dd56fe4d33291ace6d0ee7afd77852;hp=92f112e37c9c8349362c3cacc1593e8c29043a71;hpb=184e88237dea64ce48076cdd0184612d057cbafd;p=exim.git diff --git a/src/src/tod.c b/src/src/tod.c index 92f112e37..9aa845c82 100644 --- a/src/src/tod.c +++ b/src/src/tod.c @@ -1,10 +1,8 @@ -/* $Cambridge: exim/src/src/tod.c,v 1.4 2007/01/08 10:50:18 ph10 Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2007 */ +/* Copyright (c) University of Cambridge 1995 - 2009 */ /* See the file NOTICE for conditions of use and distribution. */ /* A function for returning the time of day in various formats */ @@ -34,17 +32,19 @@ a leading zero for the full stamp, since Ustrftime() doesn't provide this option. Argument: type of timestamp required: - tod_bsdin BSD inbox format - tod_epoch Unix epoch format - tod_full full date and time - tod_log log file data line format, - with zone if log_timezone is TRUE - tod_log_bare always without zone - tod_log_datestamp for log file names when datestamped - tod_log_zone always with zone - tod_mbx MBX inbox format - tod_zone just the timezone offset - tod_zulu time in 8601 zulu format + tod_bsdin BSD inbox format + tod_epoch Unix epoch format + tod_epochl Unix epoch/usec format + tod_full full date and time + tod_log log file data line format, + with zone if log_timezone is TRUE + tod_log_bare always without zone + tod_log_datestamp_daily for log file names when datestamped daily + tod_log_datestamp_monthly for log file names when datestamped monthly + tod_log_zone always with zone + tod_mbx MBX inbox format + tod_zone just the timezone offset + tod_zulu time in 8601 zulu format Returns: pointer to fixed buffer containing the timestamp */ @@ -52,9 +52,19 @@ Returns: pointer to fixed buffer containing the timestamp uschar * tod_stamp(int type) { -time_t now = time(NULL); +time_t now; struct tm *t; +if (type == tod_epoch_l) + { + struct timeval tv; + gettimeofday(&tv, NULL); + (void) sprintf(CS timebuf, "%ld%06ld", tv.tv_sec, tv.tv_usec ); /* Unix epoch/usec format */ + return timebuf; + } + +now = time(NULL); + /* Vary log type according to timezone requirement */ if (type == tod_log) type = log_timezone? tod_log_zone : tod_log_bare; @@ -91,16 +101,25 @@ switch(type) /* Format used as suffix of log file name when 'log_datestamp' is active. For testing purposes, it changes the file every second. */ - case tod_log_datestamp: #ifdef TESTING_LOG_DATESTAMP + case tod_log_datestamp_daily: + case tod_log_datestamp_monthly: (void) 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: (void) sprintf(CS timebuf, "%04d%02d%02d", 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday); - #endif break; + case tod_log_datestamp_monthly: + (void) sprintf(CS timebuf, "%04d%02d", + 1900 + t->tm_year, 1 + t->tm_mon); + break; + #endif + /* Format used in BSD inbox separator lines. Sort-of documented in RFC 976 ("UUCP Mail Interchange Format Standard") but only by example, not by explicit definition. The examples show no timezone offsets, and some MUAs