]> Trent Huber's Code - cbs.git/commitdiff
Update to strrchr() and dprintf()
authorTrent Huber <trentmhuber@gmail.com>
Sun, 13 Apr 2025 08:42:10 +0000 (04:42 -0400)
committerTrent Huber <trentmhuber@gmail.com>
Sun, 13 Apr 2025 08:42:10 +0000 (04:42 -0400)
cbs.c

diff --git a/cbs.c b/cbs.c
index 027a7df4f148641b8de2feb6d4f8f2174c6f3ef6..24359f0ebfbe85328c84bd7f66cc29bf0c701620 100644 (file)
--- a/cbs.c
+++ b/cbs.c
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <sys/errno.h>
 #include <sys/stat.h>
+#include <sys/wait.h>
 #include <unistd.h>
 
 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;