[project @ 2004-12-14 13:31:44 by malcolm]
[ghc-base.git] / System / Directory.hs
index 62072a2..d3133d4 100644 (file)
@@ -62,8 +62,13 @@ module System.Directory
     , 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__
@@ -79,9 +84,6 @@ import System.Posix.Types
 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
 
@@ -441,6 +443,8 @@ renameFile opath npath =
       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.
@@ -470,6 +474,7 @@ copyFile fromFPath toFPath =
                                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
@@ -502,6 +507,11 @@ foreign import ccall unsafe "realpath"
                               -> 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 
@@ -513,11 +523,7 @@ findExecutable binary = do
   path <- getEnv "PATH"
   search (parseSearchPath path)
   where
-#ifdef mingw32_TARGET_OS
-    fileName = binary `joinFileExt` "exe"
-#else
-    fileName = binary
-#endif
+    fileName = binary `joinFileExt` drop 1 exeExt
 
     search :: [FilePath] -> IO (Maybe FilePath)
     search [] = return Nothing
@@ -527,7 +533,15 @@ findExecutable binary = do
        if b then return (Just path)
              else search ds
 
+-- ToDo: This should be determined via autoconf (AC_EXEEXT)
+exeExt :: String
+#ifdef mingw32_TARGET_OS
+exeExt = ".exe"
+#else
+exeExt = ""
+#endif
 
+#ifdef __GLASGOW_HASKELL__
 {- |@'getDirectoryContents' dir@ returns a list of /all/ entries
 in /dir/.