#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"
n = stuffline(ctl, buf);
if (n != -1)
{
- time_t now;
-
buf[0] = '\t';
if (good_addresses == 0)
{
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);
}
}
#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. */
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 */
}
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
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);
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 */