From: krasimir Date: Thu, 20 Oct 2005 18:07:53 +0000 (+0000) Subject: [project @ 2005-10-20 18:07:53 by krasimir] X-Git-Tag: cmm-merge2~6 X-Git-Url: http://git.megacz.com/?p=haskell-directory.git;a=commitdiff_plain;h=7feacc7a21ee9d19134f1bf5429831632ca846ca [project @ 2005-10-20 18:07:53 by krasimir] The original version of @findExecutable@ was looking only in the $PATH but under Windows the executables are searched in the current directory, in $PATH and in some other places too. The new version is based on @SearchPath@ function from Win32 API. This is more consistent with @system@ and @rawSystem@ --- diff --git a/System/Directory.hs b/System/Directory.hs index 5ff3e77..21bdbf4 100644 --- a/System/Directory.hs +++ b/System/Directory.hs @@ -576,7 +576,27 @@ canonicalizePath fpath = return fpath -- such executable. For example (findExecutable \"ghc\") -- gives you the path to GHC. findExecutable :: String -> IO (Maybe FilePath) -findExecutable binary = do +findExecutable binary = +#if defined(mingw32_HOST_OS) + withCString binary $ \c_binary -> + withCString ('.':exeExtension) $ \c_ext -> + allocaBytes long_path_size $ \pOutPath -> + alloca $ \ppFilePart -> do + res <- c_SearchPath nullPtr c_binary c_ext (fromIntegral long_path_size) pOutPath ppFilePart + if res > 0 && res < fromIntegral long_path_size + then do fpath <- peekCString pOutPath + return (Just fpath) + else return Nothing + +foreign import stdcall unsafe "SearchPath" + c_SearchPath :: CString + -> CString + -> CString + -> CInt + -> CString + -> Ptr CString + -> IO CInt +#else path <- getEnv "PATH" search (parseSearchPath path) where @@ -589,6 +609,8 @@ findExecutable binary = do b <- doesFileExist path if b then return (Just path) else search ds +#endif + #ifdef __GLASGOW_HASKELL__ {- |@'getDirectoryContents' dir@ returns a list of /all/ entries