+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)