diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2016-04-10 14:36:16 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2016-04-10 14:36:16 +0200 |
commit | 8a3177f96dd4c3694242d0686762c455a9d010fd (patch) | |
tree | dc33f65dbb40abd8b9fae22833d52998b985bfad | |
parent | fe6bc99b1ed59c428ffe5da44eafcf3712d3d80d (diff) |
remove basename, just use last part of the path...
... as a bonus it also saves an allocation.
-rw-r--r-- | sfeed_frames.c | 7 | ||||
-rw-r--r-- | sfeed_html.c | 5 | ||||
-rw-r--r-- | sfeed_mbox.c | 3 | ||||
-rw-r--r-- | sfeed_plain.c | 3 | ||||
-rw-r--r-- | sfeed_tail.c | 3 | ||||
-rw-r--r-- | util.c | 21 |
6 files changed, 10 insertions, 32 deletions
diff --git a/sfeed_frames.c b/sfeed_frames.c index 64fbbc8..35fe07e 100644 --- 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 index a98e64b..2e60ad3 100644 --- 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 index 8f55525..413318f 100644 --- 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 index 78cfae0..ee836b5 100644 --- 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 index f131b8e..fbbcba0 100644 --- 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); @@ -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 |