summaryrefslogtreecommitdiff
path: root/sfeed_plain.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2016-02-27 16:21:30 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2016-02-27 16:21:30 +0100
commit13927fc6083c3d134e456ccfafb953c6cea17662 (patch)
treee34286bfbef190e29a49ed8a12fd5565d7e36f1a /sfeed_plain.c
parentfc6c2a381742aba4deaf8538fa2c85750361a2d9 (diff)
various improvements
- pledge tools and add define to enable it on platforms that support it, currently only OpenBSD 5.9+ - separate getline and parseline functionality. - use murmur3 hash instead of jenkins1: faster and less collisions. - make some error messages a bit more clear, for example with path truncation. - some small cleanups, move printutf8pad to util.
Diffstat (limited to 'sfeed_plain.c')
-rw-r--r--sfeed_plain.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/sfeed_plain.c b/sfeed_plain.c
index 82bfcdd..4de3b4d 100644
--- a/sfeed_plain.c
+++ b/sfeed_plain.c
@@ -4,7 +4,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <wchar.h>
#include "util.h"
@@ -12,36 +11,15 @@ static time_t comparetime;
static char *line;
static size_t linesize;
-/* print `len' columns of characters. If string is shorter pad the rest
- * with characters `pad`. */
-static void
-printutf8pad(FILE *fp, const char *s, size_t len, int pad)
-{
- wchar_t w;
- size_t n = 0, i;
- int r;
-
- for (i = 0; *s && n < len; i++, s++) {
- if (ISUTF8(*s)) {
- if ((r = mbtowc(&w, s, 4)) == -1)
- break;
- if ((r = wcwidth(w)) == -1)
- r = 1;
- n += (size_t)r;
- }
- putc(*s, fp);
- }
- for (; n < len; n++)
- putc(pad, fp);
-}
-
static void
printfeed(FILE *fp, const char *feedname)
{
char *fields[FieldLast];
time_t parsedtime;
- while (parseline(&line, &linesize, fields, fp) > 0) {
+ while (getline(&line, &linesize, fp) > 0) {
+ if (!parseline(line, fields))
+ break;
parsedtime = 0;
strtotime(fields[FieldUnixTimestamp], &parsedtime);
@@ -65,6 +43,9 @@ main(int argc, char *argv[])
char *name;
int i;
+ if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1)
+ err(1, "pledge");
+
if ((comparetime = time(NULL)) == -1)
err(1, "time");
/* 1 day is old news */