{-# LINE 1 "System/Posix/DynamicLinker/ByteString.hsc" #-}
{-# LANGUAGE Safe #-}
module System.Posix.DynamicLinker.ByteString (
module System.Posix.DynamicLinker.Prim,
dlopen,
dlsym,
dlerror,
dlclose,
withDL, withDL_,
undl,
)
where
import System.Posix.DynamicLinker.Common
import System.Posix.DynamicLinker.Prim
import Control.Exception ( bracket )
import Foreign
import System.Posix.ByteString.FilePath
dlopen :: RawFilePath -> [RTLDFlags] -> IO DL
dlopen :: RawFilePath -> [RTLDFlags] -> IO DL
dlopen RawFilePath
path [RTLDFlags]
flags = forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
path forall a b. (a -> b) -> a -> b
$ \CString
p -> Ptr () -> DL
DLHandle forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
forall a. String -> (a -> Bool) -> IO a -> IO a
throwDLErrorIf String
"dlopen" (forall a. Eq a => a -> a -> Bool
== forall a. Ptr a
nullPtr) (CString -> CInt -> IO (Ptr ())
c_dlopen CString
p ([RTLDFlags] -> CInt
packRTLDFlags [RTLDFlags]
flags))
withDL :: RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO a
withDL :: forall a. RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO a
withDL RawFilePath
file [RTLDFlags]
flags DL -> IO a
f = forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (RawFilePath -> [RTLDFlags] -> IO DL
dlopen RawFilePath
file [RTLDFlags]
flags) (DL -> IO ()
dlclose) DL -> IO a
f
withDL_ :: RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO ()
withDL_ :: forall a. RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO ()
withDL_ RawFilePath
file [RTLDFlags]
flags DL -> IO a
f = forall a. RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO a
withDL RawFilePath
file [RTLDFlags]
flags DL -> IO a
f forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return ()