createDirectoryIfMissing
) where
-#if __GLASGOW_HASKELL__ < 603
-#include "config.h"
-#endif
+#include "../../includes/ghcconfig.h"
import System.Environment (getEnv)
-import System.FilePath
+import System.Directory.Internals
#if __GLASGOW_HASKELL__ > 600
import Control.Exception ( bracket )
import Control.Monad ( when )
import Foreign.Marshal.Alloc ( allocaBytes )
import System.IO (IOMode(..), openBinaryFile, hGetBuf, hPutBuf, hClose)
import System.IO.Error ( try )
-import GHC.IOBase ( IOException(..) )
+import GHC.IOBase ( IOException(..), IOErrorType(..) )
#else
import System.IO ( try )
#endif
-#if __GLASGOW_HASKELL__ && defined(mingw32_TARGET_OS)
+#if __GLASGOW_HASKELL__ && defined(mingw32_HOST_OS)
import Foreign.Ptr
import Foreign.C
#endif
getAppUserDataDirectory :: String -> IO FilePath
getAppUserDataDirectory appName = do
-#if __GLASGOW_HASKELL__ && defined(mingw32_TARGET_OS)
+#if __GLASGOW_HASKELL__ && defined(mingw32_HOST_OS)
allocaBytes long_path_size $ \pPath -> do
r <- c_SHGetFolderPath nullPtr csidl_APPDATA nullPtr 0 pPath
+ when (r<0) (raiseUnsupported "Compat.Directory.getAppUserDataDirectory")
s <- peekCString pPath
return (s++'\\':appName)
#else
return (path++'/':'.':appName)
#endif
-#if __GLASGOW_HASKELL__ && defined(mingw32_TARGET_OS)
-foreign import stdcall unsafe "SHGetFolderPathA"
+#if __GLASGOW_HASKELL__ && defined(mingw32_HOST_OS)
+foreign import ccall unsafe "directory.h __hscore_getFolderPath"
c_SHGetFolderPath :: Ptr ()
-> CInt
-> Ptr ()
-> IO CInt
-- __compat_long_path_size defined in cbits/directory.c
-foreign import ccall unsafe "__compat_long_path_size"
+foreign import ccall unsafe "directory.h __compat_long_path_size"
long_path_size :: Int
-foreign import ccall unsafe "__hscore_CSIDL_APPDATA" csidl_APPDATA :: CInt
+foreign import ccall unsafe "directory.h __hscore_CSIDL_APPDATA" csidl_APPDATA :: CInt
+
+raiseUnsupported loc =
+ ioError (IOError Nothing UnsupportedOperation loc "unsupported operation" Nothing)
#endif
path <- getEnv "PATH"
search (parseSearchPath path)
where
-#ifdef mingw32_TARGET_OS
+#ifdef mingw32_HOST_OS
fileName = binary `joinFileExt` "exe"
#else
fileName = binary