From 583d11401294c962f5ad3296221c2de7823fb7d6 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 28 Mar 2025 15:33:38 -0400 Subject: [PATCH] Add platform check for /proc/self/exe --- src/tomo.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tomo.c b/src/tomo.c index 21ebed2..9233244 100644 --- a/src/tomo.c +++ b/src/tomo.c @@ -31,7 +31,10 @@ #define run_cmd(...) ({ const char *_cmd = String(__VA_ARGS__); if (verbose) print("\033[34;1m", _cmd, "\033[m"); popen(_cmd, "w"); }) #define array_text(arr) Text$join(Text(" "), arr) +#ifdef __linux__ +// Only on Linux is /proc/self/exe available static struct stat compiler_stat; +#endif static const char *paths_str(Array_t paths) { Text_t result = EMPTY_TEXT; @@ -88,6 +91,7 @@ typedef struct { #endif int main(int argc, char *argv[]) { +#ifdef __linux__ // Get the file modification time of the compiler, so we // can recompile files after changing the compiler: char compiler_path[PATH_MAX]; @@ -97,6 +101,7 @@ int main(int argc, char *argv[]) compiler_path[count] = '\0'; if (stat(compiler_path, &compiler_stat) != 0) err(1, "Could not find age of compiler"); +#endif USE_COLOR = getenv("COLOR") ? strcmp(getenv("COLOR"), "1") == 0 : isatty(STDOUT_FILENO); if (getenv("NO_COLOR") && getenv("NO_COLOR")[0] != '\0') @@ -595,9 +600,11 @@ bool is_stale(Path_t path, Path_t relative_to) if (stat(Path$as_c_string(path), &target_stat) != 0) return true; +#ifdef __linux__ // Any file older than the compiler is stale: if (target_stat.st_mtime < compiler_stat.st_mtime) return true; +#endif struct stat relative_to_stat; if (stat(Path$as_c_string(relative_to), &relative_to_stat) != 0)