diff --git a/dtool/src/dtoolutil/filename.cxx b/dtool/src/dtoolutil/filename.cxx index 04191ffbaf..a7c26c0885 100644 --- a/dtool/src/dtoolutil/filename.cxx +++ b/dtool/src/dtoolutil/filename.cxx @@ -711,6 +711,30 @@ is_directory() const { return isdir; } +//////////////////////////////////////////////////////////////////// +// Function: Filename::is_executable +// Access: Public +// Description: Returns true if the filename exists and is +// executable +//////////////////////////////////////////////////////////////////// +bool Filename:: +is_executable() const { + if (!exists()) { +#ifdef WIN32_VC + // no access() in windows, but to our advantage executables can only + // end in .exe or .com + string stmp = to_os_specific(); + stmp = stmp.substr(stmp.rfind(".") + 1); + if ((stmp == "exe") || (stmp == "com")) + return true; +#else /* WIN32_VC */ + if (access(to_os_specific().c_str(), X_OK) == 0) + return true; +#endif /* WIN32_VC */ + } + return false; +} + //////////////////////////////////////////////////////////////////// // Function: Filename::compare_timestamps // Access: Public diff --git a/dtool/src/dtoolutil/filename.h b/dtool/src/dtoolutil/filename.h index 56db7e8186..40d8fe32c4 100644 --- a/dtool/src/dtoolutil/filename.h +++ b/dtool/src/dtoolutil/filename.h @@ -129,6 +129,7 @@ PUBLISHED: bool exists() const; bool is_regular_file() const; bool is_directory() const; + bool is_executable() const; int compare_timestamps(const Filename &other, bool this_missing_is_old = true, bool other_missing_is_old = true) const;