summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README3
-rw-r--r--sfeed.c1
-rw-r--r--sfeed_atom.c1
-rw-r--r--sfeed_frames.c1
-rw-r--r--sfeed_gopher.c1
-rw-r--r--sfeed_html.c1
-rw-r--r--sfeed_mbox.c1
-rw-r--r--sfeed_opml_import.c1
-rw-r--r--sfeed_plain.c1
-rw-r--r--sfeed_twtxt.c1
-rw-r--r--sfeed_web.c1
-rw-r--r--sfeed_xmlenc.c1
-rw-r--r--util.c39
-rw-r--r--util.h8
14 files changed, 49 insertions, 12 deletions
diff --git a/README b/README
index 2fef8b2..2877912 100644
--- a/README
+++ b/README
@@ -117,7 +117,8 @@ OS tested
- FreeBSD
- DragonFlyBSD
- Windows (cygwin gcc, mingw).
-- HaikuOS (using libbsd).
+- HaikuOS
+- SerenityOS
- FreeDOS (djgpp).
- FUZIX (sdcc -mz80).
diff --git a/sfeed.c b/sfeed.c
index 086031a..645342c 100644
--- a/sfeed.c
+++ b/sfeed.c
@@ -1,7 +1,6 @@
#include <sys/types.h>
#include <ctype.h>
-#include <err.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
diff --git a/sfeed_atom.c b/sfeed_atom.c
index 8935db5..66698e8 100644
--- a/sfeed_atom.c
+++ b/sfeed_atom.c
@@ -1,6 +1,5 @@
#include <sys/types.h>
-#include <err.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
diff --git a/sfeed_frames.c b/sfeed_frames.c
index dc225d9..89838cc 100644
--- a/sfeed_frames.c
+++ b/sfeed_frames.c
@@ -1,6 +1,5 @@
#include <sys/types.h>
-#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/sfeed_gopher.c b/sfeed_gopher.c
index 28dcb9d..606e452 100644
--- a/sfeed_gopher.c
+++ b/sfeed_gopher.c
@@ -1,6 +1,5 @@
#include <sys/types.h>
-#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/sfeed_html.c b/sfeed_html.c
index 9a03901..d8abda7 100644
--- a/sfeed_html.c
+++ b/sfeed_html.c
@@ -1,6 +1,5 @@
#include <sys/types.h>
-#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/sfeed_mbox.c b/sfeed_mbox.c
index b6d3705..a734504 100644
--- a/sfeed_mbox.c
+++ b/sfeed_mbox.c
@@ -1,4 +1,3 @@
-#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/sfeed_opml_import.c b/sfeed_opml_import.c
index 6eef0ca..0844b5c 100644
--- a/sfeed_opml_import.c
+++ b/sfeed_opml_import.c
@@ -1,5 +1,4 @@
#include <ctype.h>
-#include <err.h>
#include <stdio.h>
#include <strings.h>
diff --git a/sfeed_plain.c b/sfeed_plain.c
index 1b11a71..28b36e6 100644
--- a/sfeed_plain.c
+++ b/sfeed_plain.c
@@ -1,6 +1,5 @@
#include <sys/types.h>
-#include <err.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
diff --git a/sfeed_twtxt.c b/sfeed_twtxt.c
index 2b171ba..b7d7fc4 100644
--- a/sfeed_twtxt.c
+++ b/sfeed_twtxt.c
@@ -1,6 +1,5 @@
#include <sys/types.h>
-#include <err.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
diff --git a/sfeed_web.c b/sfeed_web.c
index a715731..2d77d4c 100644
--- a/sfeed_web.c
+++ b/sfeed_web.c
@@ -1,5 +1,4 @@
#include <ctype.h>
-#include <err.h>
#include <stdio.h>
#include <strings.h>
diff --git a/sfeed_xmlenc.c b/sfeed_xmlenc.c
index a5ad2b6..c6a43d4 100644
--- a/sfeed_xmlenc.c
+++ b/sfeed_xmlenc.c
@@ -1,5 +1,4 @@
#include <ctype.h>
-#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
diff --git a/util.c b/util.c
index e1ff9bd..c43bdfc 100644
--- a/util.c
+++ b/util.c
@@ -1,5 +1,6 @@
#include <ctype.h>
#include <errno.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -7,6 +8,44 @@
#include "util.h"
+/* print to stderr, print error message of errno and exit().
+ Unlike BSD err() it does not prefix __progname */
+__dead void
+err(int exitstatus, const char *fmt, ...)
+{
+ va_list ap;
+ int saved_errno;
+
+ saved_errno = errno;
+
+ if (fmt) {
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, ": ");
+ }
+ fprintf(stderr, "%s\n", strerror(saved_errno));
+
+ exit(exitstatus);
+}
+
+/* print to stderr and exit().
+ Unlike BSD errx() it does not prefix __progname */
+__dead void
+errx(int exitstatus, const char *fmt, ...)
+{
+ va_list ap;
+
+ if (fmt) {
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ }
+ fputs("\n", stderr);
+
+ exit(exitstatus);
+}
+
/* check if string has a non-empty scheme / protocol part */
int
uri_hasscheme(const char *s)
diff --git a/util.h b/util.h
index 15d6702..1570d67 100644
--- a/util.h
+++ b/util.h
@@ -38,6 +38,14 @@ enum {
FieldLast
};
+/* hint for compilers and static analyzers that a function exits */
+#ifndef __dead
+#define __dead
+#endif
+
+__dead void err(int, const char *, ...);
+__dead void errx(int, const char *, ...);
+
int uri_format(char *, size_t, struct uri *);
int uri_hasscheme(const char *);
int uri_makeabs(struct uri *, struct uri *, struct uri *);