mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-01 16:33:02 +01:00
common: Add new function gnupg_gmtime.
* common/gettime.c (gnupg_gmtime): New. (gnupg_get_isotime): Use it. Also take care of an gmtime_t returning an error. -- The fix in gnupg_get_isotime is only to cover up a theoretical broken time (e.g. a value of (time_t)(-2) which is not mapped beyond 2038 on 32 bit systems). Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
f6670100b7
commit
5d60c7f7e0
@ -71,6 +71,29 @@ gnupg_get_time ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Wrapper around gmtime_r.
|
||||||
|
|
||||||
|
On systems without gmtime_r this implementation works within gnupg
|
||||||
|
because we use only one thread a time. FIXME: An independent
|
||||||
|
library may use gmtime in one of its own thread (or via
|
||||||
|
npth_enter/npth_leave) - in this case we run into a problem. The
|
||||||
|
solution would be to use a mutex here. */
|
||||||
|
struct tm *
|
||||||
|
gnupg_gmtime (const time_t *timep, struct tm *result)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_GMTIME_R
|
||||||
|
return gmtime_r (timep, result);
|
||||||
|
#else
|
||||||
|
struct tm *tp;
|
||||||
|
|
||||||
|
tp = gmtime (timep);
|
||||||
|
if (tp)
|
||||||
|
memcpy (result, tp, sizeof *result);
|
||||||
|
return tp;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return the current time (possibly faked) in ISO format. */
|
/* Return the current time (possibly faked) in ISO format. */
|
||||||
void
|
void
|
||||||
gnupg_get_isotime (gnupg_isotime_t timebuf)
|
gnupg_get_isotime (gnupg_isotime_t timebuf)
|
||||||
@ -82,16 +105,15 @@ gnupg_get_isotime (gnupg_isotime_t timebuf)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct tm *tp;
|
struct tm *tp;
|
||||||
#ifdef HAVE_GMTIME_R
|
|
||||||
struct tm tmbuf;
|
struct tm tmbuf;
|
||||||
|
|
||||||
tp = gmtime_r (&atime, &tmbuf);
|
tp = gnupg_gmtime (&atime, &tmbuf);
|
||||||
#else
|
if (!tp)
|
||||||
tp = gmtime (&atime);
|
*timebuf = 0;
|
||||||
#endif
|
else
|
||||||
snprintf (timebuf, 16, "%04d%02d%02dT%02d%02d%02d",
|
snprintf (timebuf, 16, "%04d%02d%02dT%02d%02d%02d",
|
||||||
1900 + tp->tm_year, tp->tm_mon+1, tp->tm_mday,
|
1900 + tp->tm_year, tp->tm_mon+1, tp->tm_mday,
|
||||||
tp->tm_hour, tp->tm_min, tp->tm_sec);
|
tp->tm_hour, tp->tm_min, tp->tm_sec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
typedef char gnupg_isotime_t[16];
|
typedef char gnupg_isotime_t[16];
|
||||||
|
|
||||||
time_t gnupg_get_time (void);
|
time_t gnupg_get_time (void);
|
||||||
|
struct tm *gnupg_gmtime (const time_t *timep, struct tm *result);
|
||||||
void gnupg_get_isotime (gnupg_isotime_t timebuf);
|
void gnupg_get_isotime (gnupg_isotime_t timebuf);
|
||||||
void gnupg_set_time (time_t newtime, int freeze);
|
void gnupg_set_time (time_t newtime, int freeze);
|
||||||
int gnupg_faked_time_p (void);
|
int gnupg_faked_time_p (void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user