FIX #3086: use System.Win32.getTemporaryDirectory
[haskell-directory.git] / System / Directory.hs
index 2579c02..1f38b14 100644 (file)
@@ -800,30 +800,11 @@ The operating system has no notion of current directory.
 getCurrentDirectory :: IO FilePath
 getCurrentDirectory = do
 #ifdef mingw32_HOST_OS
-  -- XXX: should use something from Win32
-  p <- mallocBytes long_path_size
-  go p long_path_size
-  where go p bytes = do
-         p' <- c_getcwd p (fromIntegral bytes)
-         if p' /= nullPtr 
-            then do s <- peekCString p'
-                    free p'
-                    return s
-            else do errno <- getErrno
-                    if errno == eRANGE
-                       then do let bytes' = bytes * 2
-                               p'' <- reallocBytes p bytes'
-                               go p'' bytes'
-                       else throwErrno "getCurrentDirectory"
+  System.Win32.getCurrentDirectory
 #else
   System.Posix.getWorkingDirectory
 #endif
 
-#ifdef mingw32_HOST_OS
-foreign import ccall unsafe "getcwd"
-   c_getcwd   :: Ptr CChar -> CSize -> IO (Ptr CChar)
-#endif
-
 {- |If the operating system has a notion of current directories,
 @'setCurrentDirectory' dir@ changes the current
 directory of the calling process to /dir/.
@@ -902,6 +883,8 @@ getModificationTime name =
  withFileStatus "getModificationTime" name $ \ st ->
  modificationTime st
 
+#endif /* !__HUGS__ */
+
 withFileStatus :: String -> FilePath -> (Ptr CStat -> IO a) -> IO a
 withFileStatus loc name f = do
   modifyIOError (`ioeSetFileName` name) $
@@ -944,7 +927,6 @@ foreign import ccall unsafe "__hscore_S_IXUSR" s_IXUSR :: CMode
 foreign import ccall unsafe "__hscore_S_IFDIR" s_IFDIR :: CMode
 #endif
 
-#endif /* !__HUGS__ */
 
 #ifdef __GLASGOW_HASKELL__
 foreign import ccall unsafe "__hscore_long_path_size"
@@ -1091,9 +1073,7 @@ The function doesn\'t verify whether the path exists.
 getTemporaryDirectory :: IO FilePath
 getTemporaryDirectory = do
 #if defined(mingw32_HOST_OS)
-  allocaBytes long_path_size $ \pPath -> do
-     _r <- c_GetTempPath (fromIntegral long_path_size) pPath
-     peekCString pPath
+  System.Win32.getTemporaryDirectory
 #else
   getEnv "TMPDIR"
 #if !__NHC__
@@ -1117,8 +1097,6 @@ foreign import ccall unsafe "__hscore_CSIDL_APPDATA"  csidl_APPDATA  :: CInt
 foreign import ccall unsafe "__hscore_CSIDL_WINDOWS"  csidl_WINDOWS  :: CInt
 foreign import ccall unsafe "__hscore_CSIDL_PERSONAL" csidl_PERSONAL :: CInt
 
-foreign import stdcall unsafe "GetTempPathA" c_GetTempPath :: CInt -> CString -> IO CInt
-
 raiseUnsupported :: String -> IO ()
 raiseUnsupported loc = 
    ioException (ioeSetErrorString (mkIOError UnsupportedOperation loc Nothing Nothing) "unsupported operation")