From f21638c9e3b614bc0be6903b1fb75543f9619a7b Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 31 Oct 2003 12:11:57 +0000 Subject: * util.h (gnupg_isotime_t): New. (gnupg_copy_time): New. * gettime.c (gnupg_get_isotime): New. --- common/gettime.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'common/gettime.c') diff --git a/common/gettime.c b/common/gettime.c index a7914d348..ed1d0c819 100644 --- a/common/gettime.c +++ b/common/gettime.c @@ -46,6 +46,32 @@ gnupg_get_time () return current - timewarp; } + +/* Return the current time (possibly faked) in ISO format. */ +void +gnupg_get_isotime (gnupg_isotime_t timebuf) +{ + time_t atime = gnupg_get_time (); + + if (atime < 0) + *timebuf = 0; + else + { + struct tm *tp; +#ifdef HAVE_GMTIME_R + struct tm tmbuf; + + tp = gmtime_r (&atime, &tmbuf); +#else + tp = gmtime (&atime); +#endif + sprintf (timebuf,"%04d%02d%02dT%02d%02d%02d", + 1900 + tp->tm_year, tp->tm_mon+1, tp->tm_mday, + tp->tm_hour, tp->tm_min, tp->tm_sec); + } +} + + /* set the time to NEWTIME so that gnupg_get_time returns a time starting with this one. With FREEZE set to 1 the returned time will never change. Just for completeness, a value of (time_t)-1 -- cgit v1.2.3