From 0a043101cf6c94b391204006f3cd33091fe9e061 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 20 Apr 2010 11:52:33 +0000 Subject: [PATCH] Add a separate header for time related fucntions. --- common/ChangeLog | 10 ++++++++++ common/gettime.c | 18 +++++++++++++++++ common/gettime.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ common/util.h | 42 +-------------------------------------- 4 files changed, 80 insertions(+), 41 deletions(-) create mode 100644 common/gettime.h diff --git a/common/ChangeLog b/common/ChangeLog index dce7cb3f6..93a213322 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -10,6 +10,16 @@ * t-exechelp.c (test_close_all_fds): Use dummy variables to silence gcc warning. +2010-04-15 Werner Koch + + * util.h: Factor time related fucntions out to ... + * gettime.h: New. + (gnupg_copy_time): Move to ... + * gettime.c (gnupg_copy_time): New. + + * sysutils.c (gnupg_setenv) [!W32CE]: Add missing return. + (gnupg_unsetenv) [!W32CE]: Add missing return. + 2010-04-14 Werner Koch * Makefile.am (noinst_LIBRARIES) [W32CE]: Exclude libsimple-pwquery. diff --git a/common/gettime.c b/common/gettime.c index 52f94b535..42261f96a 100644 --- a/common/gettime.c +++ b/common/gettime.c @@ -27,6 +27,7 @@ #include "util.h" #include "i18n.h" +#include "gettime.h" static unsigned long timewarp; static enum { NORMAL = 0, FROZEN, FUTURE, PAST } timemode; @@ -507,6 +508,23 @@ dump_isotime (const gnupg_isotime_t t) } +/* Copy one ISO date to another, this is inline so that we can do a + minimal sanity check. A null date (empty string) is allowed. */ +void +gnupg_copy_time (gnupg_isotime_t d, const gnupg_isotime_t s) +{ + if (*s) + { + if ((strlen (s) != 15 || s[8] != 'T')) + BUG(); + memcpy (d, s, 15); + d[15] = 0; + } + else + *d = 0; +} + + /* Add SECONDS to ATIME. SECONDS may not be negative and is limited to about the equivalent of 62 years which should be more then enough for our purposes. */ diff --git a/common/gettime.h b/common/gettime.h new file mode 100644 index 000000000..731be569b --- /dev/null +++ b/common/gettime.h @@ -0,0 +1,51 @@ +/* gettime.h - Wrapper for time functions + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#ifndef GNUPG_COMMON_GETTIME_H +#define GNUPG_COMMON_GETTIME_H + +#include /* We need time_t. */ +#include /* We need gpg_error_t. */ + + +/* A type to hold the ISO time. Note that this this is the same as + the the KSBA type ksba_isotime_t. */ +typedef char gnupg_isotime_t[16]; + +time_t gnupg_get_time (void); +void gnupg_get_isotime (gnupg_isotime_t timebuf); +void gnupg_set_time (time_t newtime, int freeze); +int gnupg_faked_time_p (void); +u32 make_timestamp (void); +u32 scan_isodatestr (const char *string); +time_t isotime2epoch (const char *string); +void epoch2isotime (gnupg_isotime_t timebuf, time_t atime); +u32 add_days_to_timestamp (u32 stamp, u16 days); +const char *strtimevalue (u32 stamp); +const char *strtimestamp (u32 stamp); /* GMT */ +const char *isotimestamp (u32 stamp); /* GMT */ +const char *asctimestamp (u32 stamp); /* localized */ +gpg_error_t add_seconds_to_isotime (gnupg_isotime_t atime, int nseconds); +gpg_error_t add_days_to_isotime (gnupg_isotime_t atime, int ndays); +gpg_error_t check_isotime (const gnupg_isotime_t atime); +void dump_isotime (const gnupg_isotime_t atime); +void gnupg_copy_time (gnupg_isotime_t d, const gnupg_isotime_t s); + + +#endif /*GNUPG_COMMON_GETTIME_H*/ diff --git a/common/util.h b/common/util.h index e197ea7a3..6fd874166 100644 --- a/common/util.h +++ b/common/util.h @@ -21,7 +21,6 @@ #define GNUPG_COMMON_UTIL_H #include /* We need this for the memory function protos. */ -#include /* We need time_t. */ #include /* We need errno. */ #include /* We need gpg_error_t. */ @@ -43,6 +42,7 @@ #include "../common/dynload.h" #include "init.h" +#include "gettime.h" /* Redefine asprintf by our estream version which uses our own memory allocator.. */ @@ -98,46 +98,6 @@ out_of_core (void) return gpg_error_from_syserror (); } -/* A type to hold the ISO time. Note that this this is the same as - the the KSBA type ksba_isotime_t. */ -typedef char gnupg_isotime_t[16]; - - -/*-- gettime.c --*/ -time_t gnupg_get_time (void); -void gnupg_get_isotime (gnupg_isotime_t timebuf); -void gnupg_set_time (time_t newtime, int freeze); -int gnupg_faked_time_p (void); -u32 make_timestamp (void); -u32 scan_isodatestr (const char *string); -time_t isotime2epoch (const char *string); -void epoch2isotime (gnupg_isotime_t timebuf, time_t atime); -u32 add_days_to_timestamp (u32 stamp, u16 days); -const char *strtimevalue (u32 stamp); -const char *strtimestamp (u32 stamp); /* GMT */ -const char *isotimestamp (u32 stamp); /* GMT */ -const char *asctimestamp (u32 stamp); /* localized */ -gpg_error_t add_seconds_to_isotime (gnupg_isotime_t atime, int nseconds); -gpg_error_t add_days_to_isotime (gnupg_isotime_t atime, int ndays); -gpg_error_t check_isotime (const gnupg_isotime_t atime); -void dump_isotime (const gnupg_isotime_t atime); - -/* Copy one ISO date to another, this is inline so that we can do a - minimal sanity check. A null date (empty string) is allowed. */ -static inline void -gnupg_copy_time (gnupg_isotime_t d, const gnupg_isotime_t s) -{ - if (*s) - { - if ((strlen (s) != 15 || s[8] != 'T')) - BUG(); - memcpy (d, s, 15); - d[15] = 0; - } - else - *d = 0; -} - /*-- signal.c --*/ void gnupg_init_signals (int mode, void (*fast_cleanup)(void));