Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
GitLab is currently being migrated to new hosting. This process should be finished by 17:00 EDT 29 March 2025.
You are on a read-only GitLab instance.
Show more breadcrumbs
Alex D
GHC
Commits
d35cec7a
Commit
d35cec7a
authored
5 years ago
by
Fraser Tweedale
Committed by
Marge Bot
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
getExecutablePath: get path from sysctl on FreeBSD
parent
90e0ab7d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/base/System/Environment/ExecutablePath.hsc
+47
-0
47 additions, 0 deletions
libraries/base/System/Environment/ExecutablePath.hsc
with
47 additions
and
0 deletions
libraries/base/System/Environment/ExecutablePath.hsc
+
47
−
0
View file @
d35cec7a
...
...
@@ -32,6 +32,14 @@ import System.Posix.Internals
import Foreign.C
import Foreign.Marshal.Array
import System.Posix.Internals
#elif defined(freebsd_HOST_OS)
import Foreign.C
import Foreign.Marshal.Alloc
import Foreign.Marshal.Array
import Foreign.Ptr
import Foreign.Storable
import System.Posix.Internals
#include <sys/sysctl.h>
#elif defined(mingw32_HOST_OS)
import Control.Exception
import Data.List
...
...
@@ -131,6 +139,45 @@ readSymbolicLink file =
getExecutablePath = readSymbolicLink $ "/proc/self/exe"
--------------------------------------------------------------------------------
-- FreeBSD
#elif defined(freebsd_HOST_OS)
foreign import ccall unsafe "sysctl"
c_sysctl
:: Ptr CInt -- MIB
-> CUInt -- MIB size
-> Ptr CChar -- old / current value buffer
-> Ptr CSize -- old / current value buffer size
-> Ptr CChar -- new value
-> CSize -- new value size
-> IO CInt -- result
getExecutablePath = do
withArrayLen mib $ \n mibPtr -> do
let mibLen = fromIntegral n
alloca $ \bufSizePtr -> do
status <- c_sysctl mibPtr mibLen nullPtr bufSizePtr nullPtr 0
case status of
0 -> do
reqBufSize <- fromIntegral <$> peek bufSizePtr
allocaBytes reqBufSize $ \buf -> do
newStatus <- c_sysctl mibPtr mibLen buf bufSizePtr nullPtr 0
case newStatus of
0 -> peekFilePath buf
_ -> barf
_ -> barf
where
barf = throwErrno "getExecutablePath"
mib =
[ (#const CTL_KERN)
, (#const KERN_PROC)
, (#const KERN_PROC_PATHNAME)
, -1 -- current process
]
--------------------------------------------------------------------------------
-- Windows
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment