X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Fcompiler%2Fmain%2FSysTools.lhs;h=876d210f90b7737a1c20b516ad3fa0b9885cc874;hb=82db18e4c12e1ed76736ee67dc365cdaebeef7d7;hp=945ae44cf19d8f6cb62bebb96f6714dcfdeeea4a;hpb=54f9adfa25afe299b7e86f6836b49647c1e3a811;p=ghc-hetmet.git diff --git a/ghc/compiler/main/SysTools.lhs b/ghc/compiler/main/SysTools.lhs index 945ae44..876d210 100644 --- a/ghc/compiler/main/SysTools.lhs +++ b/ghc/compiler/main/SysTools.lhs @@ -64,6 +64,8 @@ import System ( ExitCode(..) ) #if !defined(mingw32_TARGET_OS) import qualified Posix +#else +import Ptr ( nullPtr ) #endif #include "HsVersions.h" @@ -601,14 +603,22 @@ slash s1 s2 = s1 ++ ('/' : s2) #endif ----------------------------------------------------------------------------- --- Convert filepath into MSDOS form. --- -- Define myGetProcessId :: IO Int #ifdef mingw32_TARGET_OS -foreign import "_getpid" getProcessID :: IO Int +foreign import "_getpid" getProcessID :: IO Int -- relies on Int == Int32 on Windows +foreign import stdcall "GetCurrentDirectoryA" getCurrentDirectory :: Int32 -> CString -> IO Int32 +getExecDir :: IO (Maybe String) +getExecDir = do len <- getCurrentDirectory 0 nullPtr + buf <- mallocArray (fromIntegral len) + ret <- getCurrentDirectory len buf + if ret == 0 then return Nothing + else do s <- peekCString buf + destructArray (fromIntegral len) buf + return (Just s) #else getProcessID :: IO Int getProcessID = Posix.getProcessID +getExecDir :: IO (Maybe String) = do return Nothing #endif \end{code}