diff options
-rw-r--r-- | libraries/base/System/Environment/ExecutablePath.hsc | 16 | ||||
-rw-r--r-- | libraries/ghc-boot/GHC/BaseDir.hs | 4 |
2 files changed, 14 insertions, 6 deletions
diff --git a/libraries/base/System/Environment/ExecutablePath.hsc b/libraries/base/System/Environment/ExecutablePath.hsc index 5cb49489c5..923d61883c 100644 --- a/libraries/base/System/Environment/ExecutablePath.hsc +++ b/libraries/base/System/Environment/ExecutablePath.hsc @@ -38,7 +38,7 @@ import Data.List (isSuffixOf) import Foreign.C import Foreign.Marshal.Array import System.Posix.Internals -#elif defined(freebsd_HOST_OS) +#elif defined(freebsd_HOST_OS) || defined(netbsd_HOST_OS) import Control.Exception (catch, throw) import Foreign.C import Foreign.Marshal.Alloc @@ -92,7 +92,7 @@ getExecutablePath :: IO FilePath -- -- If the operating system provides a reliable way to determine the current -- executable, return the query action, otherwise return @Nothing@. The action --- is defined on FreeBSD, Linux, MacOS and Windows. +-- is defined on FreeBSD, Linux, MacOS, NetBSD, and Windows. -- -- Even where the query action is defined, there may be situations where no -- result is available, e.g. if the executable file was deleted while the @@ -188,9 +188,9 @@ executablePath = Just (check <$> getExecutablePath) where | otherwise = Just s -------------------------------------------------------------------------------- --- FreeBSD +-- FreeBSD / NetBSD -#elif defined(freebsd_HOST_OS) +#elif defined(freebsd_HOST_OS) || defined(netbsd_HOST_OS) foreign import ccall unsafe "sysctl" c_sysctl @@ -219,11 +219,19 @@ getExecutablePath = do where barf = throwErrno "getExecutablePath" mib = +# if defined(freebsd_HOST_OS) [ (#const CTL_KERN) , (#const KERN_PROC) , (#const KERN_PROC_PATHNAME) , -1 -- current process ] +# elif defined(netbsd_HOST_OS) + [ (#const CTL_KERN) + , (#const KERN_PROC_ARGS) + , -1 -- current process + , (#const KERN_PROC_PATHNAME) + ] +# endif executablePath = Just (fmap Just getExecutablePath `catch` f) where diff --git a/libraries/ghc-boot/GHC/BaseDir.hs b/libraries/ghc-boot/GHC/BaseDir.hs index dbbf61d02e..862e7739d2 100644 --- a/libraries/ghc-boot/GHC/BaseDir.hs +++ b/libraries/ghc-boot/GHC/BaseDir.hs @@ -23,7 +23,7 @@ import System.FilePath #if defined(mingw32_HOST_OS) import System.Environment (getExecutablePath) -- POSIX -#elif defined(darwin_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(openbsd_HOST_OS) +#elif defined(darwin_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(openbsd_HOST_OS) || defined(netbsd_HOST_OS) import System.Environment (getExecutablePath) #endif @@ -52,7 +52,7 @@ getBaseDir = Just . (\p -> p </> "lib") . rootDir <$> getExecutablePath -- that is running this function. rootDir :: FilePath -> FilePath rootDir = takeDirectory . takeDirectory . normalise -#elif defined(darwin_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(openbsd_HOST_OS) +#elif defined(darwin_HOST_OS) || defined(linux_HOST_OS) || defined(freebsd_HOST_OS) || defined(openbsd_HOST_OS) || defined(netbsd_HOST_OS) -- on unix, this is a bit more confusing. -- The layout right now is something like -- |