summaryrefslogtreecommitdiff
path: root/sfeed_atom.c
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-08-09 14:11:50 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2024-08-09 14:11:50 -0400
commit5857d82e8e596d6fda406a0c4d8d68ca7a03c124 (patch)
tree553916894dee907825360580c5d9a05c82c5af16 /sfeed_atom.c
parent3574e3cbf9d99546e868aeb995ce2c171cdc36a6 (diff)
parent19957bc272e745af7b56b79fa648e8b6b77113b1 (diff)
Merge remote-tracking branch 'upstream/master'HEADmaster
Diffstat (limited to 'sfeed_atom.c')
-rw-r--r--sfeed_atom.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/sfeed_atom.c b/sfeed_atom.c
index 1dff75b..d0b139d 100644
--- a/sfeed_atom.c
+++ b/sfeed_atom.c
@@ -1,5 +1,3 @@
-#include <sys/types.h>
-
#include <stdio.h>
#include <string.h>
#include <time.h>
@@ -22,6 +20,8 @@ printcontent(const char *s)
case '&': fputs("&amp;", stdout); break;
case '"': fputs("&quot;", stdout); break;
case '\\':
+ if (*(s + 1) == '\0')
+ break;
s++;
switch (*s) {
case 'n': putchar('\n'); break;
@@ -43,7 +43,8 @@ printfeed(FILE *fp, const char *feedname)
ssize_t linelen;
int c;
- while ((linelen = getline(&line, &linesize, fp)) > 0) {
+ while ((linelen = getline(&line, &linesize, fp)) > 0 &&
+ !ferror(stdout)) {
if (line[linelen - 1] == '\n')
line[--linelen] = '\0';
parseline(line, fields);
@@ -94,7 +95,7 @@ printfeed(FILE *fp, const char *feedname)
/* NOTE: an RSS/Atom viewer may or may not format
whitespace such as newlines.
Workaround: type="html" and <![CDATA[<pre></pre>]]> */
- fputs("\t<content type=\"text\">", stdout);
+ fputs("\t<content>", stdout);
}
printcontent(fields[FieldContent]);
fputs("</content>\n", stdout);
@@ -124,15 +125,14 @@ main(int argc, char *argv[])
if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1)
err(1, "pledge");
- if ((now = time(NULL)) == -1)
- err(1, "time");
+ if ((now = time(NULL)) == (time_t)-1)
+ errx(1, "time");
if (!(tm = gmtime_r(&now, &tmnow)))
- err(1, "gmtime_r");
+ err(1, "gmtime_r: can't get current time");
fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"
- "\t<title type=\"text\">Newsfeed</title>\n"
- "\t<author><name>sfeed</name></author>\n", stdout);
+ "\t<title>Newsfeed</title>\n", stdout);
printf("\t<id>urn:newsfeed:%lld</id>\n"
"\t<updated>%04d-%02d-%02dT%02d:%02d:%02dZ</updated>\n",
(long long)now,
@@ -141,19 +141,22 @@ main(int argc, char *argv[])
if (argc == 1) {
printfeed(stdin, "");
+ checkfileerror(stdin, "<stdin>", 'r');
} else {
for (i = 1; i < argc; i++) {
if (!(fp = fopen(argv[i], "r")))
err(1, "fopen: %s", argv[i]);
name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i];
printfeed(fp, name);
- if (ferror(fp))
- err(1, "ferror: %s", argv[i]);
+ checkfileerror(fp, argv[i], 'r');
+ checkfileerror(stdout, "<stdout>", 'w');
fclose(fp);
}
}
fputs("</feed>\n", stdout);
+ checkfileerror(stdout, "<stdout>", 'w');
+
return 0;
}