module System.Directory.ProjectRoot
where
import Control.Applicative ((<$>))
import Foreign.C (CString, newCString, peekCString)
import Foreign.Ptr (nullPtr)
import System.Directory (getCurrentDirectory)
getProjectRoot :: FilePath -> IO (Maybe FilePath)
getProjectRoot fp = do
root <- find_project_root =<< newCString fp
if root == nullPtr
then return Nothing
else Just <$> peekCString root
getProjectRootWeighted :: FilePath -> IO (Maybe FilePath)
getProjectRootWeighted fp = do
root <- find_project_root_weighted =<< newCString fp
if root == nullPtr
then return Nothing
else Just <$> peekCString root
getProjectRootCurrent :: IO (Maybe FilePath)
getProjectRootCurrent = getCurrentDirectory >>= getProjectRoot
getProjectRootWeightedCurrent :: IO (Maybe FilePath)
getProjectRootWeightedCurrent = getCurrentDirectory >>= getProjectRootWeighted
foreign import ccall "find_project_root" find_project_root :: CString -> IO CString
foreign import ccall "find_project_root_weighted" find_project_root_weighted :: CString -> IO CString