Remaining bugs in Cabal under Windows

Simon Marlow simonmar at microsoft.com
Tue Aug 17 08:59:43 EDT 2004


On 17 August 2004 13:44, Krasimir Angelov wrote:

> {-# OPTIONS -cpp #-}
> #ifdef mingw32_TARGET_OS
> {-# OPTIONS -#include "shlobj.h" #-}
> #endif
> 
> #ifdef mingw32_TARGET_OS
> import Foreign
> import Foreign.C
> #else
> import System.Environment
> #endif
> 
> getHomeDirectory :: IO FilePath
> getHomeDirectory =
> #ifdef mingw32_TARGET_OS
>   allocaBytes 1024 $ \pPath -> do
>      r <- c_SHGetFolderPath nullPtr 0x28 nullPtr 0
> pPath
>      if (r < 0)
>        then c_SHGetFolderPath nullPtr 0x05 nullPtr 0
> pPath
>        else return 0
>      peekCString pPath
> #else
>   getEnv "HOME"
> #endif
>
> getAppUserDataDirectory :: String -> IO FilePath
> getAppUserDataDirectory appName = do
> #ifdef mingw32_TARGET_OS
>   allocaBytes 1024    $ \pPath -> do
>      r <- c_SHGetFolderPath nullPtr 0x1A nullPtr 0
> pPath
>      s <- peekCString pPath
>      return (s++'\\':appName)
> #else
>   path <- getEnv "HOME"
>   return (path++'/':'.':appName)
> #endif

I'm happy for these functions to go into System.Directory, unless anyone
disagrees.  Instead of using the manifest constants (0x28, 0x05, 0x1A)
use another method to get the constants in - for libraries/base the
technique we use is to define an inline function in HsBase.h.

If you commit the code, I'll add Haddock comments.

Cheers,
	Simon


More information about the Libraries mailing list