sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 8a3177f96dd4c3694242d0686762c455a9d010fd
parent fe6bc99b1ed59c428ffe5da44eafcf3712d3d80d
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 10 Apr 2016 14:36:16 +0200

remove basename, just use last part of the path...

... as a bonus it also saves an allocation.

Diffstat:
Msfeed_frames.c | 7++++---
Msfeed_html.c | 5+++--
Msfeed_mbox.c | 3+--
Msfeed_plain.c | 3+--
Msfeed_tail.c | 3+--
Mutil.c | 21---------------------
6 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/sfeed_frames.c b/sfeed_frames.c @@ -236,8 +236,8 @@ int main(int argc, char *argv[]) { FILE *fpindex, *fpitems, *fpmenu, *fp; - int showsidebar = (argc > 1); - int i; + char *name; + int i, showsidebar = (argc > 1); struct feed *f; if (pledge("stdio rpath wpath cpath fattr", NULL) == -1) @@ -271,7 +271,8 @@ main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (!(feeds[i - 1] = calloc(1, sizeof(struct feed)))) err(1, "calloc"); - feeds[i - 1]->name = xbasename(argv[i]); + name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i]; + feeds[i - 1]->name = name; if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); diff --git a/sfeed_html.c b/sfeed_html.c @@ -81,6 +81,7 @@ int main(int argc, char *argv[]) { struct feed *f; + char *name; FILE *fp; int i; @@ -119,8 +120,8 @@ main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (!(feeds[i - 1] = calloc(1, sizeof(struct feed)))) err(1, "calloc"); - feeds[i - 1]->name = xbasename(argv[i]); - + name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i]; + feeds[i - 1]->name = name; if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); printfeed(fp, feeds[i - 1]); diff --git a/sfeed_mbox.c b/sfeed_mbox.c @@ -143,9 +143,8 @@ main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); - name = xbasename(argv[i]); + name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i]; printfeed(fp, name); - free(name); if (ferror(fp)) err(1, "ferror: %s", argv[i]); fclose(fp); diff --git a/sfeed_plain.c b/sfeed_plain.c @@ -67,9 +67,8 @@ main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); - name = xbasename(argv[i]); + name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i]; printfeed(fp, name); - free(name); if (ferror(fp)) err(1, "ferror: %s", argv[i]); fclose(fp); diff --git a/sfeed_tail.c b/sfeed_tail.c @@ -104,9 +104,8 @@ main(int argc, char *argv[]) bucket = &buckets[i - 1]; if (!(fp = fopen(argv[i], "r"))) err(1, "fopen: %s", argv[i]); - name = xbasename(argv[i]); + name = ((name = strrchr(argv[i], '/'))) ? name + 1 : argv[i]; printfeed(fp, name); - free(name); if (ferror(fp)) err(1, "ferror: %s", argv[i]); fclose(fp); diff --git a/util.c b/util.c @@ -3,7 +3,6 @@ #include <ctype.h> #include <err.h> #include <errno.h> -#include <libgen.h> #include <limits.h> #include <stdarg.h> #include <stdio.h> @@ -249,26 +248,6 @@ xmlencode(const char *s, FILE *fp) } } -/* Some implementations of basename(3) return a pointer to a static - * internal buffer (OpenBSD). Others modify the contents of `path` (POSIX). - * This is a wrapper function that is compatible with both versions. - * The program will error out if basename(3) failed, this can only happen - * with the OpenBSD version. */ -char * -xbasename(const char *path) -{ - char *p, *b; - - if (!(p = strdup(path))) - err(1, "strdup"); - if (!(b = basename(p))) - err(1, "basename"); - if (!(b = strdup(b))) - err(1, "strdup"); - free(p); - return b; -} - /* print `len' columns of characters. If string is shorter pad the rest * with characters `pad`. */ void