, getHomeDirectory
, getAppUserDataDirectory
, getUserDocumentsDirectory
+ , getTemporaryDirectory
-- * Actions on files
, removeFile -- :: FilePath -> IO ()
, getModificationTime -- :: FilePath -> IO ClockTime
) where
+import System.Environment ( getEnv )
+import System.FilePath
+import System.IO.Error
+
#ifdef __NHC__
import Directory
+import NHC.FFI
#endif /* __NHC__ */
#ifdef __HUGS__
import System.Posix.Internals
import System.Time ( ClockTime(..) )
import System.IO
-import System.IO.Error
-import System.FilePath
-import System.Environment (getEnv)
import Foreign
import Foreign.C
withCString npath $ \s2 ->
throwErrnoIfMinus1Retry_ "renameFile" (c_rename s1 s2)
+#endif /* __GLASGOW_HASKELL__ */
+
{- |@'copyFile' old new@ copies the existing file from /old/ to /new/.
If the /new/ file already exists, it is atomically replaced by the /old/ file.
Neither path may refer to an existing directory.
copyContents hFrom hTo buffer
#endif
+#ifdef __GLASGOW_HASKELL__
-- | Given path referring to a file or directory, returns a
-- canonicalized path, with the intent that two paths referring
-- to the same file\/directory will map to the same canonicalized
-> CString
-> IO CString
#endif
+#else /* !__GLASGOW_HASKELL__ */
+-- dummy implementation
+canonicalizePath :: FilePath -> IO FilePath
+canonicalizePath fpath = return fpath
+#endif /* !__GLASGOW_HASKELL__ */
-- | Given an executable file name, searches for such file
-- in the directories listed in system PATH. The returned value
path <- getEnv "PATH"
search (parseSearchPath path)
where
-#ifdef mingw32_TARGET_OS
- fileName = binary `joinFileExt` "exe"
-#else
- fileName = binary
-#endif
+ fileName = binary `joinFileExt` drop 1 exeExtension
search :: [FilePath] -> IO (Maybe FilePath)
search [] = return Nothing
if b then return (Just path)
else search ds
-
+#ifdef __GLASGOW_HASKELL__
{- |@'getDirectoryContents' dir@ returns a list of /all/ entries
in /dir/.
getEnv "HOME"
#endif
+{- | Returns the current directory for temporary files.
+
+On Unix, 'getTemporaryDirectory' returns the value of the @TMPDIR@
+environment variable or \"\/tmp\" if the variable isn\'t defined.
+On Windows, the function checks for the existence of environment variables in
+the following order and uses the first path found:
+
+* TMP environment variable.
+* TEMP environment variable.
+* USERPROFILE environment variable.
+* The Windows directory
+
+The operation may fail with:
+
+* 'UnsupportedOperation'
+The operating system has no notion of temporary directory.
+
+The function doesn\'t verify whether the path exists.
+-}
+getTemporaryDirectory :: IO FilePath
+getTemporaryDirectory = do
+#if __GLASGOW_HASKELL__ && defined(mingw32_TARGET_OS)
+ allocaBytes long_path_size $ \pPath -> do
+ r <- c_GetTempPath (fromIntegral long_path_size) pPath
+ peekCString pPath
+#else
+ catch (getEnv "TMPDIR") (\ex -> return "/tmp")
+#endif
+
#if __GLASGOW_HASKELL__ && defined(mingw32_TARGET_OS)
foreign import stdcall unsafe "SHGetFolderPath"
c_SHGetFolderPath :: Ptr ()
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 "GetTempPath" c_GetTempPath :: CInt -> CString -> IO CInt
#endif