summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPHO <pho@cielonegro.org>2022-02-08 15:50:44 +0900
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-02-09 03:56:59 -0500
commita172be07e3dce758a2325104a3a37fc8b1d20c9c (patch)
tree429d7a800ba3ab962b6cb76e27dbc81bb6ba2986
parenta39ed908abd91b7863f8bd9ddfd72bc11535c451 (diff)
downloadhaskell-a172be07e3dce758a2325104a3a37fc8b1d20c9c.tar.gz
Implement System.Environment.getExecutablePath for NetBSD
and also use it from GHC.BaseDir.getBaseDir
-rw-r--r--libraries/base/System/Environment/ExecutablePath.hsc16
-rw-r--r--libraries/ghc-boot/GHC/BaseDir.hs4
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
--