{-# LINE 1 "libraries/unix/System/Posix/DynamicLinker/ByteString.hsc" #-}
{-# LINE 2 "libraries/unix/System/Posix/DynamicLinker/ByteString.hsc" #-}
{-# LANGUAGE Safe #-}
{-# LINE 6 "libraries/unix/System/Posix/DynamicLinker/ByteString.hsc" #-}
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 Control.Monad ( liftM )
import Foreign
import System.Posix.ByteString.FilePath
dlopen :: RawFilePath -> [RTLDFlags] -> IO DL
dlopen :: RawFilePath -> [RTLDFlags] -> IO DL
dlopen RawFilePath
path [RTLDFlags]
flags = do
RawFilePath -> (CString -> IO DL) -> IO DL
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
path ((CString -> IO DL) -> IO DL) -> (CString -> IO DL) -> IO DL
forall a b. (a -> b) -> a -> b
$ \ CString
p -> do
(Ptr () -> DL) -> IO (Ptr ()) -> IO DL
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Ptr () -> DL
DLHandle (IO (Ptr ()) -> IO DL) -> IO (Ptr ()) -> IO DL
forall a b. (a -> b) -> a -> b
$ String -> (Ptr () -> Bool) -> IO (Ptr ()) -> IO (Ptr ())
forall a. String -> (a -> Bool) -> IO a -> IO a
throwDLErrorIf String
"dlopen" (Ptr () -> Ptr () -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr ()
forall a. Ptr a
nullPtr) (IO (Ptr ()) -> IO (Ptr ())) -> IO (Ptr ()) -> IO (Ptr ())
forall a b. (a -> b) -> a -> b
$ CString -> CInt -> IO (Ptr ())
c_dlopen CString
p ([RTLDFlags] -> CInt
packRTLDFlags [RTLDFlags]
flags)
withDL :: RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO a
withDL :: RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO a
withDL RawFilePath
file [RTLDFlags]
flags DL -> IO a
f = IO DL -> (DL -> IO ()) -> (DL -> IO a) -> IO a
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_ :: RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO ()
withDL_ RawFilePath
file [RTLDFlags]
flags DL -> IO a
f = RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO a
forall a. RawFilePath -> [RTLDFlags] -> (DL -> IO a) -> IO a
withDL RawFilePath
file [RTLDFlags]
flags DL -> IO a
f IO a -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()