{-# LINE 1 "System/Unix/FilePath.hsc" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LINE 2 "System/Unix/FilePath.hsc" #-}

-- | 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


{-# LINE 20 "System/Unix/FilePath.hsc" #-}

{-# LINE 21 "System/Unix/FilePath.hsc" #-}

-- |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 (4096) $ \res ->
{-# LINE 38 "System/Unix/FilePath.hsc" #-}
            throwErrnoIfNull "realpath" (c_realpath cfp res) >>= peekCString

foreign import ccall unsafe "realpath" c_realpath :: CString -> CString -> IO CString