From b763f1289b7ea8d9c836306ab6a2aa64d02e7a71 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Mon, 29 Apr 2024 14:01:32 -0400 Subject: [PATCH] fix: add macos build patch for `fs_get_creation_time` Signed-off-by: Rui Chen --- src/fs.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/fs.c b/src/fs.c index fa989d4..a84bd27 100644 --- a/src/fs.c +++ b/src/fs.c @@ -181,19 +181,27 @@ char* fs_search_directory(const char *dir_path, const char *dirname) // Function to return creation time of file double fs_get_creation_time(const char *path) { - struct statx stx; - int fd = open(path, O_RDONLY); - if (fd == -1) +#if defined(__APPLE__) || defined(__MACH__) + // Use stat on macOS to access creation time + struct stat st; + + if (stat(path, &st) != 0) { - // Error return -1; } - int ret = statx(fd, "", AT_EMPTY_PATH, STATX_ALL, &stx); - if (ret == -1) + return st.st_birthtimespec.tv_sec + st.st_birthtimespec.tv_nsec / 1e9; +#else + struct statx stx; + int fd = open(path, O_RDONLY); + if (fd == -1) + { + return -1; + } + + if (statx(fd, "", AT_EMPTY_PATH, STATX_ALL, &stx) != 0) { - // Error close(fd); return -1; } @@ -202,4 +210,5 @@ double fs_get_creation_time(const char *path) close(fd); return stx.stx_btime.tv_sec + stx.stx_btime.tv_nsec / 1e9; +#endif }