From 96eb0633bfebf6623cd6464dfafa8235e7a7fc38 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Sat, 30 Aug 2025 18:08:49 +0800 Subject: [PATCH 2/2] main.cpp: improve portability for non-Linux OS --- main.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/main.cpp b/main.cpp index 5aab23f..a71fd10 100644 --- a/main.cpp +++ b/main.cpp @@ -13,7 +13,9 @@ #include #include +#ifdef __linux__ #include +#endif #include #include #include @@ -46,6 +48,14 @@ #include "help.hpp" #include "icons.hpp" +#ifdef __APPLE__ +#define st_mtim st_mtimespec +#endif + +#ifndef ulong +typedef unsigned long ulong; +#endif + const static int TAB_MAX = 4; static const char* const TMP_FILENAME = "/tmp/minase_tmp"; @@ -2261,8 +2271,19 @@ public: auto fd = open(path.c_str(), O_RDONLY | O_DIRECTORY); if(fd == -1) return false; +#ifdef __linux__ int result = 0; result = syscall(SYS_renameat2, fd, src.c_str(), fd, dst.c_str(), RENAME_NOREPLACE); +#else + struct stat st; + if (fstatat(fd, dst.c_str(), &st, 0) == 0) { + close(fd); + addLogMessage("Can't rename file/dir (destination exists): " + path + src + " -> " + path + dst); + return false; + } + + int result = renameat(fd, src.c_str(), fd, dst.c_str()); +#endif close(fd); startTask(); @@ -4294,9 +4315,19 @@ int main(int argc, char **argv) } if(path == "") { +#ifdef __linux__ char* currentPath = get_current_dir_name(); path = std::string(currentPath) + "/"; free(currentPath); +#else + char* currentPath = getcwd(NULL, 0); + if (currentPath != NULL) { + path = std::string(currentPath) + "/"; + free(currentPath); + } else { + path = "./"; + } +#endif } Minase::PickerMode mode = Minase::PICKER_NONE; -- 2.48.0