]> Trent Huber's Code - cbs.git/commitdiff
Changes for Linux compatibility
authorTrent Huber <trentmhuber@gmail.com>
Wed, 23 Jul 2025 07:59:03 +0000 (03:59 -0400)
committerTrent Huber <trentmhuber@gmail.com>
Wed, 23 Jul 2025 07:59:03 +0000 (03:59 -0400)
cbs.c

diff --git a/cbs.c b/cbs.c
index fa4b22ecb4e98eef690f979915036531ce5ffc70..798b53c9aeabdc6439760734b8d49aafe60c3af0 100644 (file)
--- a/cbs.c
+++ b/cbs.c
 
 #ifdef __APPLE__
 #define DYEXT ".dylib"
+#define TIME st_mtimespec
 #else
 #define DYEXT ".so"
+#define TIME st_mtim
 #endif
 
 #define NONE (char *[]){NULL}
@@ -150,8 +152,8 @@ void load(char type, char *target, char **objs) {
 int after(struct stat astat, struct stat bstat) {
    struct timespec a, b;
 
-   a = astat.st_mtimespec;
-   b = bstat.st_mtimespec;
+   a = astat.TIME;
+   b = bstat.TIME;
 
    return a.tv_sec == b.tv_sec ? a.tv_nsec > b.tv_nsec : a.tv_sec > b.tv_sec;
 }
@@ -167,11 +169,10 @@ void build(char *path) {
    if (!(current = getcwd(NULL, 0)))
        err(EXIT_FAILURE, "Unable to check current directory");
 
-   exists = stat("build", &exe) != -1;
    if ((self = strcmp(absolute, current) == 0)) {
        if (stat("build.c", &src) == -1)
            err(EXIT_FAILURE, "Unable to stat `build.c'");
-       if ((leave = exists && after(exe, src))
+       if ((leave = (exists = stat("build", &exe) == 0) && after(exe, src))
            && utimensat(AT_FDCWD, "build.c", NULL, 0) == -1)
            err(EXIT_FAILURE, "Unable to update `build.c' modification time");
    } else {
@@ -183,6 +184,7 @@ void build(char *path) {
        if (chdir(path) == -1)
            err(EXIT_FAILURE, "Unable to change directory to `%s'", path);
 
+       exists = stat("build", &exe) == 0;
        leave = cpid;
    }