[project @ 2004-11-11 17:21:02 by simonmar]
[ghc-hetmet.git] / ghc / lib / compat / Compat / Directory.hs
1 {-# OPTIONS -cpp #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module      :  Compat.Directory
5 -- Copyright   :  (c) The University of Glasgow 2001-2004
6 -- License     :  BSD-style (see the file libraries/base/LICENSE)
7 -- 
8 -- Maintainer  :  libraries@haskell.org
9 -- Stability   :  provisional
10 -- Portability :  portable
11 --
12 -- Functions from System.Directory that aren't present in older versions
13 -- of that library.
14 --
15 -----------------------------------------------------------------------------
16
17 module Compat.Directory (
18         getAppUserDataDirectory,
19   ) where
20
21 #if __GLASGOW_HASKELL__ < 603
22 #include "config.h"
23 #endif
24
25 #if !defined(mingw32_TARGET_OS)
26 import System.Environment (getEnv)
27 #endif
28
29 getAppUserDataDirectory :: String -> IO FilePath
30 getAppUserDataDirectory appName = do
31 #if __GLASGOW_HASKELL__ && defined(mingw32_TARGET_OS)
32   allocaBytes long_path_size $ \pPath -> do
33      r <- c_SHGetFolderPath nullPtr csidl_APPDATA nullPtr 0 pPath
34      s <- peekCString pPath
35      return (s++'\\':appName)
36 #else
37   path <- getEnv "HOME"
38   return (path++'/':'.':appName)
39 #endif
40
41 #if __GLASGOW_HASKELL__ && defined(mingw32_TARGET_OS)
42 foreign import stdcall unsafe "SHGetFolderPath" 
43             c_SHGetFolderPath :: Ptr () 
44                               -> CInt 
45                               -> Ptr () 
46                               -> CInt 
47                               -> CString 
48                               -> IO CInt
49 #endif