Well, I finally got BSD working. The actual code was every bit the
breeze I expected it to be. This module has been verified to work
correctly under FreeBSD 7.1, but integration with other code has not
been tested. I am assuming that considering the simple nature of the
code, the unchanged type signatures should be enough to conclude that
it will work.
{-
BSD - We get the value of the 'kern.proc.pathname'
sysctl, with additional argument -1. I have
no clue that the -1 does, but it makes the
whole thing work, so it's good.
-}
{-# LANGUAGE ForeignFunctionInterface #-}
module System.Environment.Executable.BSD
( getExecutablePath, getPID ) where
import Control.Monad ( liftM )
import System.Posix ( getProcessID)
import System.BSD.Sysctl ( sysctlNameToOidArgs, sysctlReadString )
--------------------------------------------------------------------------------
getPID :: IO Int
getPID = liftM fromIntegral $ getProcessID
getExecutablePath :: IO FilePath
getExecutablePath = do
pathCtl <- sysctlNameToOidArgs "kern.proc.pathname" [-1]
sysctlReadString pathCtl
--------------------------------------------------------------------------------
--~--~---------~--~----~------------~-------~--~----~
Yi development mailing list
[email protected]
http://groups.google.com/group/yi-devel
-~----------~----~----~----~------~----~------~--~---