X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=utils%2Frunghc%2Frunghc.hs;h=4424c96096332d4c594d73c008f19ffe842d1ef3;hb=8133a9f47b99f4e65ed30551de32ad72c6b61b27;hp=aadafd9a7125ef28785770e74294187b4badc429;hpb=34cc75e1a62638f2833815746ebce0a9114dc26b;p=ghc-hetmet.git diff --git a/utils/runghc/runghc.hs b/utils/runghc/runghc.hs index aadafd9..4424c96 100644 --- a/utils/runghc/runghc.hs +++ b/utils/runghc/runghc.hs @@ -1,9 +1,5 @@ {-# LANGUAGE CPP, ForeignFunctionInterface #-} -#if __GLASGOW_HASKELL__ < 603 -#include "config.h" -#else #include "ghcconfig.h" -#endif ----------------------------------------------------------------------------- -- -- (c) The University of Glasgow, 2004 @@ -23,10 +19,7 @@ module Main (main) where import Control.Exception -import Data.Char -import Data.List import Data.Monoid -import Data.Version import System.Cmd import System.Directory import System.Environment @@ -156,15 +149,17 @@ dieProg msg = do getExecPath :: IO (Maybe String) #if defined(mingw32_HOST_OS) -getExecPath = - allocaArray len $ \buf -> do - ret <- getModuleFileName nullPtr buf len - if ret == 0 then return Nothing - else liftM Just $ peekCString buf - where len = 2048 -- Plenty, PATH_MAX is 512 under Win32. - -foreign import stdcall unsafe "GetModuleFileNameA" - getModuleFileName :: Ptr () -> CString -> Int -> IO Int32 +getExecPath = try_size 2048 -- plenty, PATH_MAX is 512 under Win32. + where + try_size size = allocaArray (fromIntegral size) $ \buf -> do + ret <- c_GetModuleFileName nullPtr buf size + case ret of + 0 -> return Nothing + _ | ret < size -> fmap Just $ peekCWString buf + | otherwise -> try_size (size * 2) + +foreign import stdcall unsafe "windows.h GetModuleFileNameW" + c_GetModuleFileName :: Ptr () -> CWString -> Word32 -> IO Word32 #else getExecPath = return Nothing #endif