]> Pileus Git - ~andy/fetchmail/commitdiff
Rationalized timestamps.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 30 Oct 1998 15:11:46 +0000 (15:11 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 30 Oct 1998 15:11:46 +0000 (15:11 -0000)
svn path=/trunk/; revision=2155

driver.c
env.c
fetchmail.c
fetchmail.h

index 6016de5123530713a7e1b10ef678d71eb8991818..33c3b48bc5a806fc4dcb27792e73998955c53461 100644 (file)
--- a/driver.c
+++ b/driver.c
 #include  <sys/time.h>
 #include  <signal.h>
 
-#ifndef HAVE_STRFTIME /* For ctime prototype */
-#include  <sys/types.h>
-#include  <time.h>
-#endif
-
 #ifdef HAVE_RES_SEARCH
 #include <netdb.h>
 #include "mx.h"
@@ -866,8 +861,6 @@ static int readheaders(int sock, long fetchlen, long reallen, struct query *ctl,
            n = stuffline(ctl, buf);
            if (n != -1)
            {
-               time_t  now;
-
                buf[0] = '\t';
                if (good_addresses == 0)
                {
@@ -890,24 +883,8 @@ static int readheaders(int sock, long fetchlen, long reallen, struct query *ctl,
                else
                    buf[1] = '\0';
 
-               time(&now);
-#ifdef HAVE_STRFTIME
-               /*
-                * Conform to RFC822.  This is typically going to emit
-                * a three-letter timezone for %Z, which is going to
-                * be marked "obsolete syntax" in 822bis.  Note that we
-                * generate a 4-digit year here.
-                */
-               strftime(buf + strlen(buf), sizeof(buf) - strlen(buf), 
-                        "%a, %d %b %Y %H:%M:%S %Z\r\n", localtime(&now));
-#else
-               /*
-                * This is really just a portability fallback, as the
-                * date format ctime(3) emits is not RFC822
-                * conformant.
-                */
-               strcat(buf, ctime(&now));
-#endif /* HAVE_STRFTIME */
+               strcat(buf, rfc822timestamp());
+               strcat(buf, "\r\n");
                n = stuffline(ctl, buf);
            }
        }
diff --git a/env.c b/env.c
index 7fe360406a00ddb69998529414c410b309da26b0..da8168d6aff2b528180252b5bedb9cb7fb7154c7 100644 (file)
--- a/env.c
+++ b/env.c
 #ifdef HAVE_GETHOSTBYNAME
 #include <netdb.h>
 #endif /* HAVE_GETHOSTBYNAME */
+#ifndef HAVE_STRFTIME /* For ctime prototype */
+#include  <sys/types.h>
+#include  <time.h>
+#endif
 #include "fetchmail.h"
 
 extern char *getenv(); /* needed on sysV68 R3V7.1. */
@@ -99,6 +103,36 @@ char *host_fqdn(void)
        return(xstrdup(tmpbuf));
 }
 
+char *rfc822timestamp(void)
+/* return a timestamp in RFC822 form */
+{
+    time_t     now;
+    static char buf[40];
+
+    time(&now);
+#ifdef HAVE_STRFTIME
+    /*
+     * Conform to RFC822.  This is typically going to emit
+     * a three-letter timezone for %Z, which is going to
+     * be marked "obsolete syntax" in 822bis.  Note that we
+     * generate a 4-digit year here, avoiding Y2K hassles.
+     * Note: max length of this timestamp in an English locale
+     * should be 29 chars, assuming a 3-character timezone.
+     */
+    strftime(buf, sizeof(buf)-1, 
+            "%a, %d %b %Y %H:%M:%S %Z", localtime(&now));
+#else
+    /*
+     * This is really just a portability fallback, as the
+     * date format ctime(3) emits is not RFC822
+     * conformant.
+     */
+    strcpy(buf, ctime(&now));
+    buf[strlen(buf)-1] = '\0'; /* remove trailing \n */
+#endif /* HAVE_STRFTIME */
+
+    return(buf);
+}
 
 const char *showproto(int proto)
 /* protocol index to protocol name mapping */
index 4923eceacb175be61a6fe988729cc488ba3dffcf..9a05dc82aef6a13a8b16d32e21b84879112b9fa6 100644 (file)
@@ -600,12 +600,7 @@ int main (int argc, char **argv)
            }
 
            if (outlevel >= O_VERBOSE)
-           {
-               time_t  now;
-
-               time(&now);
-               error(0, -1, "fetchmail: sleeping at %s", ctime(&now));
-           }
+               error(0, -1, "fetchmail: sleeping at %s", rfc822timestamp());
 
            /*
             * With this simple hack, we make it possible for a foreground 
@@ -712,12 +707,7 @@ int main (int argc, char **argv)
                signal(SIGHUP, SIG_IGN);
 
            if (outlevel >= O_VERBOSE)
-           {
-               time_t  now;
-
-               time(&now);
-               error(0, -1, "awakened at %s", ctime(&now));
-           }
+               error(0, -1, "awakened at %s", rfc822timestamp());
        }
     } while
        (run.poll_interval);
index 73e0b8ec605e8f285c80ff1c5f6913e27070c670..657804346f2dcde3b2855a1133c9cfecc0fc459c 100644 (file)
@@ -447,6 +447,7 @@ const char *showproto(int);
 void dump_config(struct runctl *runp, struct query *querylist);
 int is_host_alias(const char *, struct query *);
 char *host_fqdn(void);
+char *rfc822timestamp(void);
 #ifdef SDPS_ENABLE
 char *sdps_envto;
 #endif /* SDPS_ENABLE */