Browse Source

whee, new functionality

Cary Sandvig 25 years ago
parent
commit
9a80bf5ea2
2 changed files with 25 additions and 0 deletions
  1. 24 0
      dtool/src/dtoolutil/filename.cxx
  2. 1 0
      dtool/src/dtoolutil/filename.h

+ 24 - 0
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

+ 1 - 0
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;