X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=System%2FDirectory.hs;h=ec4e5a703ff5494472bdd5a3ab1216a85fd3f93c;hb=d968106fdef283b30d06ae45fa2f87329e1c2269;hp=5ff3e77ec7e3805d79721661519f49b1517a3d58;hpb=2a5112bdcf1fb97caeb87c1ba76f49957d86d201;p=haskell-directory.git diff --git a/System/Directory.hs b/System/Directory.hs index 5ff3e77..ec4e5a7 100644 --- a/System/Directory.hs +++ b/System/Directory.hs @@ -576,7 +576,28 @@ 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 + do path <- getEnv "PATH" search (parseSearchPath path) where @@ -589,6 +610,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