diff --git a/tools/src/universal.cpp b/tools/src/universal.cpp index 849174cc..6c23ddca 100644 --- a/tools/src/universal.cpp +++ b/tools/src/universal.cpp @@ -44,12 +44,6 @@ namespace { using namespace dwarfs::tool; using namespace std::string_view_literals; -#ifdef _WIN32 -#define EXE_EXT ".exe" -#else -#define EXE_EXT "" -#endif - constexpr dwarfs::sorted_array_map functions{ std::pair{"dwarfs"sv, &dwarfs_main}, std::pair{"mkdwarfs"sv, &mkdwarfs_main}, @@ -57,6 +51,22 @@ constexpr dwarfs::sorted_array_map functions{ std::pair{"dwarfsextract"sv, &dwarfsextract_main}, }; +bool looks_like_executable(std::filesystem::path const& path) { + auto ext = path.extension().string(); + + if (ext.empty()) { + return true; + } + +#ifdef _WIN32 + if (ext == ".exe") { + return true; + } +#endif + + return false; +} + } // namespace int SYS_MAIN(int argc, sys_char** argv) { @@ -64,7 +74,7 @@ int SYS_MAIN(int argc, sys_char** argv) { // first, see if we are called as a copy/hardlink/symlink - if (auto ext = path.extension().string(); ext.empty() || ext == EXE_EXT) { + if (looks_like_executable(path)) { auto stem = path.stem().string(); if (auto it = functions.find(stem); it != functions.end()) { return main_adapter(it->second).safe(argc, argv);