summaryrefslogtreecommitdiff
path: root/sfeed_mbox.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2015-10-05 00:01:28 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2015-10-05 00:01:28 +0200
commit0c0066919ede9a3ab03a35bea3df22a156747629 (patch)
tree5f4b9f6f859f94d72102a6ea2c2458d563170a9a /sfeed_mbox.c
parent019bb0178ec6e97bf1bc780c027407b14fdbd407 (diff)
sfeed_mbox: do host lookup and current time once at startup, not per feed
Diffstat (limited to 'sfeed_mbox.c')
-rw-r--r--sfeed_mbox.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/sfeed_mbox.c b/sfeed_mbox.c
index 6b14786..96ec02e 100644
--- 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 {