commit 0c0066919ede9a3ab03a35bea3df22a156747629
parent 019bb0178ec6e97bf1bc780c027407b14fdbd407
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Mon, 5 Oct 2015 00:01:28 +0200
sfeed_mbox: do host lookup and current time once at startup, not per feed
Diffstat:
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/sfeed_mbox.c b/sfeed_mbox.c
@@ -13,6 +13,7 @@
static char *line;
static size_t linesize;
+static char host[256], *user, mtimebuf[32];
/* jenkins one-at-a-time hash, used for Message-Id */
static uint32_t
@@ -76,22 +77,9 @@ static void
printfeed(FILE *fp, const char *feedname)
{
struct tm tm;
- char *fields[FieldLast], timebuf[32], mtimebuf[32];
- char host[256], *user;
+ char *fields[FieldLast], timebuf[32];
time_t parsedtime;
- if (!(user = getenv("USER")))
- user = "you";
- if (gethostname(host, sizeof(host)) == -1)
- err(1, "gethostname");
-
- if ((parsedtime = time(NULL)) == -1)
- err(1, "time");
- if (!gmtime_r(&parsedtime, &tm))
- errx(1, "gmtime_r: can't get current time");
- if (!strftime(mtimebuf, sizeof(mtimebuf), "%a %b %d %H:%M:%S %Y", &tm))
- errx(1, "strftime: can't format current time");
-
while (parseline(&line, &linesize, fields, fp) > 0) {
parsedtime = 0;
strtotime(fields[FieldUnixTimestamp], &parsedtime);
@@ -140,10 +128,23 @@ printfeed(FILE *fp, const char *feedname)
int
main(int argc, char *argv[])
{
+ struct tm tm;
+ time_t t;
FILE *fp;
char *name;
int i;
+ if (!(user = getenv("USER")))
+ user = "you";
+ if (gethostname(host, sizeof(host)) == -1)
+ err(1, "gethostname");
+ if ((t = time(NULL)) == -1)
+ err(1, "time");
+ if (!gmtime_r(&t, &tm))
+ errx(1, "gmtime_r: can't get current time");
+ if (!strftime(mtimebuf, sizeof(mtimebuf), "%a %b %d %H:%M:%S %Y", &tm))
+ errx(1, "strftime: can't format current time");
+
if (argc == 1) {
printfeed(stdin, "");
} else {