1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
{-# LANGUAGE ForeignFunctionInterface #-}
-- | The function splitFileName is taken from missingh, at the moment
-- missingh will not build under sid.
module System.Unix.FilePath
(dirName,
baseName,
realpath,
(<++>))
where
import Data.List
import System.FilePath (makeRelative, (</>), takeFileName, dropFileName)
--import Text.Regex
import Foreign.C
import Foreign.Marshal.Array
#include <limits.h>
#include <stdlib.h>
-- |Concatenate two paths, making sure there is exactly one path separator.
a <++> b = a </> (makeRelative "" b)
-- |Use dropFileName
dirName :: FilePath -> FilePath
dirName = dropFileName
-- |Use takeFileName
baseName :: FilePath -> String
baseName = takeFileName
-- |resolve all references to /./, /../, extra slashes, and symlinks
realpath :: FilePath -> IO FilePath
realpath fp =
withCString fp $ \cfp ->
allocaArray (#const PATH_MAX) $ \res ->
throwErrnoIfNull "realpath" (c_realpath cfp res) >>= peekCString
foreign import ccall unsafe "realpath" c_realpath :: CString -> CString -> IO CString
|