From cf44895dc00f6a776ea716a8f1a16e1faedd9ee2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 3 Aug 2016 10:34:36 +0200 Subject: Only PATH-search for .exe files on Windows --- butl/process.cxx | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'butl') diff --git a/butl/process.cxx b/butl/process.cxx index b207ee5..6b41165 100644 --- a/butl/process.cxx +++ b/butl/process.cxx @@ -12,6 +12,7 @@ # include // _open_osfhandle(), _get_osfhandle(), _close() # include // _O_TEXT +# include // _stricmp() @@ CASE # include // _MAX_PATH, getenv() # include // stat # include // stat(), S_IS* @@ -281,20 +282,20 @@ namespace butl s += f.string (); r = path (move (s)); // Move back into result. - // Check that the file exist without checking for permissions, etc. + // Unless there is already the .exe extension, add it. Note that running + // .bat files requires starting cmd.exe and passing the batch file as an + // argument (see CreateProcess() for deails). So if/when we decide to + // support those, it will have to be handled differently. // - struct stat info; - if (stat (r.string ().c_str (), &info) == 0 && S_ISREG (info.st_mode)) - return true; + const char* e (r.extension ()); + if (e == nullptr || _stricmp (e, "exe") != 0) // @@ CASE + r += ".exe"; - // Also try the path with the .exe extension. + // Only check that the file exists since the executable mode is set + // according to the file extension. // - r += ".exe"; - - if (stat (r.string ().c_str (), &info) == 0 && S_ISREG (info.st_mode)) - return true; - - return false; + struct stat si; + return stat (r.string ().c_str (), &si) == 0 && S_ISREG (si.st_mode); }; // The search order is documented in CreateProcess(). First we look in -- cgit v1.1