[Pkg-gnupg-commit] [gnupg2] 61/160: common: New function rfctimestamp.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Fri Jul 15 09:36:36 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch upstream
in repository gnupg2.

commit 1ddf5b846fc058171af5f2784dad866b73eb0205
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Jun 28 15:45:53 2016 +0200

    common: New function rfctimestamp.
    
    * common/gettime.c (rfctimestamp): New.
    --
    
    It is surprisingly hard to create an RFC-2822 compliant Date value.
    The problem is that strftime uses the current locale but the RFC
    requires that the English names are used.  This code is pretty simply
    and avoid the extra problem of figuring out the correct timezone;
    instead UTC is used.  For the planned use case this is anyway better.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 common/gettime.c | 33 +++++++++++++++++++++++++++++++++
 common/gettime.h |  1 +
 2 files changed, 34 insertions(+)

diff --git a/common/gettime.c b/common/gettime.c
index 115f725..dd9c196 100644
--- a/common/gettime.c
+++ b/common/gettime.c
@@ -723,6 +723,39 @@ asctimestamp (u32 stamp)
 }
 
 
+/* Return the timestamp STAMP in RFC-2822 format.  This is always done
+ * in the C locale.  We return the gmtime to avoid computing the
+ * timezone. The caller must release the returned string.
+ *
+ * Example: "Mon, 27 Jun 2016 1:42:00 +0000".
+ */
+char *
+rfctimestamp (u32 stamp)
+{
+  time_t atime = stamp;
+  struct tm tmbuf, *tp;
+
+
+  if (IS_INVALID_TIME_T (atime))
+    {
+      gpg_err_set_errno (EINVAL);
+      return NULL;
+    }
+
+  tp = gnupg_gmtime (&atime, &tmbuf);
+  if (!tp)
+    return NULL;
+  return xtryasprintf ("%.3s, %02d %.3s %04d %02d:%02d:%02d +0000",
+                       ("SunMonTueWedThuFriSat" + (tp->tm_wday%7)*3),
+                       tp->tm_mday,
+                       ("JanFebMarAprMayJunJulAugSepOctNovDec"
+                        + (tp->tm_mon%12)*3),
+                       tp->tm_year + 1900,
+                       tp->tm_hour,
+                       tp->tm_min,
+                       tp->tm_sec);
+}
+
 
 static int
 days_per_year (int y)
diff --git a/common/gettime.h b/common/gettime.h
index cbc257a..08cb3b1 100644
--- a/common/gettime.h
+++ b/common/gettime.h
@@ -59,6 +59,7 @@ const char *strtimevalue (u32 stamp);
 const char *strtimestamp (u32 stamp); /* GMT */
 const char *isotimestamp (u32 stamp); /* GMT */
 const char *asctimestamp (u32 stamp); /* localized */
+char *rfctimestamp (u32 stamp);       /* RFC format, malloced. */
 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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list