From 49229842a680dd79cc19794e37ff5d0e2f3e2e6b Mon Sep 17 00:00:00 2001 From: Trent Huber Date: Sun, 13 Apr 2025 04:42:10 -0400 Subject: [PATCH] Update to strrchr() and dprintf() --- cbs.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cbs.c b/cbs.c index 027a7df..24359f0 100644 --- a/cbs.c +++ b/cbs.c @@ -4,6 +4,7 @@ #include #include #include +#include #include extern char **environ; @@ -13,12 +14,12 @@ char **cflags, **lflags; void error(char *fmt, ...) { va_list args; - fprintf(stderr, "cbs: "); + dprintf(STDERR_FILENO, "cbs: "); va_start(args, fmt); - vfprintf(stderr, fmt, args); + vdprintf(STDERR_FILENO, fmt, args); va_end(args); - if (errno) fprintf(stderr, ": %s", strerror(errno)); - fprintf(stderr, "\n"); + if (errno) dprintf(STDERR_FILENO, ": %s", strerror(errno)); + dprintf(STDERR_FILENO, "\n"); exit(EXIT_FAILURE); } @@ -37,9 +38,9 @@ char *extend(char *path, char *ext) { if (!path) return NULL; - bp = (bp = rindex(path, '/')) ? bp + 1 : path; + bp = (bp = strrchr(path, '/')) ? bp + 1 : path; d = bp - path; - b = (ep = rindex(bp, '.')) ? ep - bp : (ep = ext, strlen(bp)); + b = (ep = strrchr(bp, '.')) ? ep - bp : (ep = ext, strlen(bp)); if (*ext == '!') ep = ext + 1; e = strlen(ep); l = strncmp(ep, ".a", e) == 0 || strncmp(ep, ".dylib", e) == 0 ? 3 : 0; -- 2.51.0